Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Decision: REQUEST_CHANGES – The server mostly works, but it fails a core requirement for path parsing, which is a blocker.
- Critical issue (src/createServer.js): When deriving
parts, the code usespathname.slice(1)and thensplit('/'), which includes empty segments. This violates the requirement that doubled slashes be ignored and that/yields an empty array. For example,/currently produces[''], and//hello//worldincludes empty strings. Please update thepartscomputation to filter out empty strings, e.g.,const parts = url.pathname.split('/').filter(Boolean);so that/→[]and//hello//world→['hello','world']. - What you did well: You set
Content-Type: application/jsonand usedURL+Object.fromEntries(url.searchParams)to produce string query values as required. - Minor improvement (optional): Construct a single
URLinstance and reuse it to avoid double parsing.
Once the empty segment filtering is added, this should meet all requirements. Good work overall—just fix the path parts handling to pass the edge cases.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/createServer.js
Outdated
| /* Write your code here */ | ||
| // Return instance of http.Server class | ||
| const server = http.createServer((req, res) => { | ||
| const relativePath = new URL(req.url, 'http://localhost').pathname.slice(1); |
There was a problem hiding this comment.
Using pathname.slice(1) to create relativePath then splitting later can leave empty strings for consecutive slashes or produce [''] for root path. This breaks the requirement that doubled slashes be ignored and that / results in an empty parts array. Consider not relying on slice(1) + raw split without filtering. What should parts be for / and //hello//world? (The description requires [] and ['hello','world'] respectively.)
src/createServer.js
Outdated
| const relativePath = new URL(req.url, 'http://localhost').pathname.slice(1); | ||
| const params = new URL(req.url, 'http://localhost'); | ||
| const query = Object.fromEntries(params.searchParams); | ||
| const parts = relativePath.split('/'); |
There was a problem hiding this comment.
Splitting relativePath with relativePath.split('/') will produce empty segments for consecutive slashes and for an empty string. Update this line to filter out empty strings, for example:
const parts = relativePath.split('/').filter(Boolean);This ensures / -> [] and //hello//world -> ['hello','world'], matching the task requirements.
src/createServer.js
Outdated
| const server = http.createServer((req, res) => { | ||
| const relativePath = new URL(req.url, 'http://localhost').pathname.slice(1); | ||
| const params = new URL(req.url, 'http://localhost'); | ||
| const query = Object.fromEntries(params.searchParams); |
There was a problem hiding this comment.
Creating query with Object.fromEntries(params.searchParams) is fine — it yields string values for parameter values (including "" for parameters without a value). One note: if the same query key appears multiple times, Object.fromEntries will keep the last value; if multi-values are important you may need a different approach. Otherwise this satisfies the requirement that query values are strings.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Decision: APPROVE
Your server meets the requirements: it correctly parses the pathname into parts (ignoring empty segments from doubled slashes), builds a query object with string values, sets Content-Type: application/json, and responds with exactly { parts, query }. It handles root / as an empty parts array and requests without a query as an empty query object.
Minor suggestion (non-blocking): repeated query keys will keep only the last value when using Object.fromEntries(url.searchParams). If you ever need multi-valued parameters, consider aggregating values per key, e.g., mapping url.searchParams into arrays when keys repeat.
Nice work—clean, compliant, and clear implementation.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.