Skip to content

Commit a80fe4f

Browse files
committed
refactor: Switch frontend API endpoints to production Render backend
1 parent 4e0f1c5 commit a80fe4f

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

chat-app/frontend/script.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let lastIdSeen = -1;
33
async function getAllMessages() {
44
try {
55
const response = await fetch(
6-
`http://localhost:3000/messages?since=${lastIdSeen}`,
6+
`https://iswanna-chat-app-backend.onrender.com/messages?since=${lastIdSeen}`,
77
);
88

99
const data = await response.json();
@@ -41,9 +41,12 @@ async function getAllMessages() {
4141
likeButton.textContent = "Like";
4242

4343
likeButton.addEventListener("click", async () => {
44-
await fetch(`http://localhost:3000/messages/${message.id}/like`, {
45-
method: "POST",
46-
});
44+
await fetch(
45+
`https://iswanna-chat-app-backend.onrender.com/messages/${message.id}/like`,
46+
{
47+
method: "POST",
48+
},
49+
);
4750
});
4851

4952
// put it all together
@@ -76,16 +79,19 @@ formElement.addEventListener("submit", async (event) => {
7679

7780
try {
7881
// Send the data
79-
const response = await fetch("http://localhost:3000/messages", {
80-
method: "POST",
81-
headers: {
82-
"Content-Type": "application/json",
82+
const response = await fetch(
83+
"https://iswanna-chat-app-backend.onrender.com/messages",
84+
{
85+
method: "POST",
86+
headers: {
87+
"Content-Type": "application/json",
88+
},
89+
body: JSON.stringify({
90+
sender: senderValue,
91+
text: messageValue,
92+
}),
8393
},
84-
body: JSON.stringify({
85-
sender: senderValue,
86-
text: messageValue,
87-
}),
88-
});
94+
);
8995

9096
if (response.ok) {
9197
// clear the sender and message input values

0 commit comments

Comments
 (0)