NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | Chat App frontend#77
NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | Chat App frontend#77ZabihollahNamazi wants to merge 11 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
Code works on normal circumstances. My comments are mainly surrounding handling of
errors and unusual user input.
Can you also include these items in the PR description?
- A description of the additional features you have implemented
- A link to the deployed frontend on the CYF hosting environment
- A link to the deployed backend on the CYF hosting environment
| document.addEventListener("DOMContentLoaded", () => { | ||
| const messagesList = document.getElementById("messages-list"); | ||
| const form = document.getElementById("message-form"); | ||
| const input = document.getElementById("message-input"); |
There was a problem hiding this comment.
How can you make this named constant more meaningful?
| const res = await fetch(BACKEND_URL); | ||
| const messages = await res.json(); |
| li.innerHTML = ` | ||
| <div><strong>${msg.username}</strong></div> | ||
| <div>${msg.text}</div> | ||
| <small>${msg.timeStamp}</small> | ||
| `; |
There was a problem hiding this comment.
Currently HTML injection is possible. Can you update the code or propose a solution to prevent it from happening?
| await fetch(BACKEND_URL, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| username: usernameInput.value, | ||
| text: input.value, | ||
| }), | ||
| }); |
There was a problem hiding this comment.
-
No input sanitization and validation ?
-
What if the operation fails or return a "username and text required" error response?
| const { username, text } = req.body; | ||
|
|
||
| if (!username || !text) { | ||
| return res.status(400).json({ error: "username and text required" }); | ||
| } |
There was a problem hiding this comment.
It's good practice to validate all request inputs.
A more robust implementation should also account for potential failures on line 19 and include appropriate error handling.
In this exercise, let's assume the request is always coming from the code in script.js. So no change needed.
| messages.push({ | ||
| username, | ||
| text, | ||
| timeStamp: new Date().toLocaleTimeString(), |
There was a problem hiding this comment.
Can you suggest a strategy to ensure that users in different time zones see timestamps in their respective local time zones?
Self checklist
could you please check my pr ? thank you very much