Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Decision: APPROVE — The implementation meets the core requirements: it parses the path into parts (ignoring empty segments), parses query parameters into a query object, and responds with valid JSON using standard Node APIs.
Minor, non-blocking notes for robustness and clarity:
- On src/createServer.js, when calling
decodeURIComponenton the entire path, a malformed percent-encoding (e.g., a stray%) can throw and crash the handler. Consider decoding each segment individually (e.g., split by/andmap(seg => decodeURIComponent(seg))) or wrapping in try/catch to avoid a crash. - When iterating
URLSearchParams, duplicate keys (e.g.,?a=1&a=2) overwrite earlier values. If you need to preserve all values, considerparams.getAll(key)and storing arrays like{ a: ["1", "2"] }. - Small cleanup: using
res.writeHead(200, { 'Content-Type': 'application/json' })is preferred over including a reason phrase.
Overall, nicely done—clear, concise, and correct for the task. The suggestions above are optional improvements to handle edge cases more gracefully.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| // Return instance of http.Server class | ||
| const server = http.createServer((req, res) => { | ||
| const [path, queryString = ''] = req.url.split('?'); | ||
| const parts = decodeURIComponent((path || '/').slice(1)) |
There was a problem hiding this comment.
You call decodeURIComponent on the entire path string. If the path contains malformed percent-encoding (e.g. a stray %), decodeURIComponent will throw and crash the request handler. The task doesn't require handling malformed encoding, but to be more robust consider decoding each path segment individually instead of the whole path at once, for example:
const parts = (path || '/')
.slice(1)
.split('/')
.filter(Boolean)
.map(seg => decodeURIComponent(seg));This avoids an exception caused by one bad segment and still satisfies the requirement to ignore empty segments.
| for (const [key, value] of params) { | ||
| query[key] = value; |
There was a problem hiding this comment.
URLSearchParams iteration yields each key/value pair, and the current code sets query[key] = value, which means if the same key appears multiple times (e.g. ?a=1&a=2) the last value wins and earlier ones are overwritten. The task example uses single values, but the description says "all queryParams" — if you must preserve multiple values, consider storing arrays or using params.getAll(key) and produce "a": ["1", "2"]. If single-string values are acceptable, no change is required, but be aware of this behavior.
No description provided.