Skip to content

Commit d45de2c

Browse files
committed
refactor: Make frontend backend URL configurable via API_BASE_URL
- Add API_BASE_URL placeholder constant - Replace hardcoded production URLs with `${API_BASE_URL}` for: - GET /messages - POST /messages/:id/like - POST /messages (form submission)
1 parent eb16726 commit d45de2c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

chat-app/frontend/script.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
const API_BASE_URL = "${API_BASE_URL}";
2+
13
let lastIdSeen = -1;
24

35
async function getAllMessages() {
46
try {
57
const response = await fetch(
6-
`https://iswanna-chat-app-backend.hosting.codeyourfuture.io/messages?since=${lastIdSeen}`,
8+
`${API_BASE_URL}/messages?since=${lastIdSeen}`,
79
);
810

911
const data = await response.json();
@@ -42,7 +44,7 @@ async function getAllMessages() {
4244

4345
likeButton.addEventListener("click", async () => {
4446
await fetch(
45-
`https://iswanna-chat-app-backend.hosting.codeyourfuture.io/messages/${message.id}/like`,
47+
`${API_BASE_URL}/messages/${message.id}/like`,
4648
{
4749
method: "POST",
4850
},
@@ -88,7 +90,7 @@ formElement.addEventListener("submit", async (event) => {
8890
try {
8991
// Send the data
9092
const response = await fetch(
91-
"https://iswanna-chat-app-backend.hosting.codeyourfuture.io/messages",
93+
`${API_BASE_URL}/messages`,
9294
{
9395
method: "POST",
9496
headers: {

0 commit comments

Comments
 (0)