Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Approved. The implementation in src/createServer.js meets the core requirements: it starts an HTTP server, correctly parses the pathname into parts, parses the query into a string-valued query object, sets Content-Type: application/json, and returns valid JSON. Nice use of the WHATWG URL API and clean, concise logic.
Minor suggestions (non-blocking):
- Line ~10:
new URL(req.url, http://${req.headers.host} )can throw ifreq.headers.hostis undefined. Consider a fallback base:const base = http://${req.headers.host || 'localhost'}to avoid edge-case crashes. - Duplicate query keys: current behavior is “last value wins” because of
url.searchParams.forEach((value, key) => { query[key] = value; }). Either document this explicitly or, if you prefer, change to another consistent policy (e.g., keep first or collect arrays). - Optional polish: fix any minor typos in variable names, remove unused ESLint directives, and you can omit setting
res.statusMessagewhen status is 200.
Overall, the server behaves as required. Great job—just consider the small robustness tweak and documenting duplicate key behavior for clarity.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| /* Write your code here */ | ||
| // Return instance of http.Server class | ||
| const server = http.createServer((req, res) => { | ||
| const url = new URL(req.url, `http://${req.headers.host}`); |
There was a problem hiding this comment.
You're constructing the URL with new URL(req.url, http://${req.headers.host}) which will throw if req.headers.host is undefined in some environments. Consider providing a fallback base (for example: use http://localhost when req.headers.host is missing) so the server doesn't crash in edge cases.
| url.searchParams.forEach((value, key) => { | ||
| query[key] = value; | ||
| }); |
There was a problem hiding this comment.
The code uses url.searchParams.forEach(...) and assigns each query[key] = value, which means if a query parameter appears multiple times, the last occurrence will overwrite earlier ones. The task allows a consistent approach, but please document this behavior or change it if you intended a different policy (e.g., keep first value or collect values into arrays).
No description provided.