Skip to content

add task solution#423

Open
Taipan-4ik wants to merge 1 commit intomate-academy:masterfrom
Taipan-4ik:develop
Open

add task solution#423
Taipan-4ik wants to merge 1 commit intomate-academy:masterfrom
Taipan-4ik:develop

Conversation

@Taipan-4ik
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 if req.headers.host is 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.statusMessage when 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

  1. Rate AI review example

/* 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}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +15 to +17
url.searchParams.forEach((value, key) => {
query[key] = value;
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants