Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on setting up the server and handling query parameters! The code is clean and the use of the URL constructor for parsing is a solid choice.
However, there is one critical requirement that isn't met, which is why I'm requesting changes. The server needs to correctly handle URL pathnames with multiple or trailing slashes.
Issue: Incorrect Pathname Parsing
- Location:
src/createServer.js - Requirement: The
partsarray in the JSON response must contain the segments of the URL'spathname, with all empty strings removed. - Problem: Your current implementation,
urlParams.pathname.split('/').slice(1), doesn't handle all cases correctly. For example:- A path like
/a//bresults in['a', '', 'b']. - A path with a trailing slash like
/a/b/results in['a', 'b', ''].
- A path like
The requirement is to ignore doubled slashes and trailing slashes, which means the final
partsarray should not contain any empty strings.
Suggested Fix
Instead of using slice(1), which only removes the first element of the array, you should filter out all empty strings after splitting the pathname. The Array.prototype.filter() method is perfect for this.
// A more robust way to get the path parts
const pathName = urlParams.pathname.split('/').filter(Boolean);This small change will ensure your code correctly handles all variations of the URL path as required.
Your handling of query parameters, especially with duplicate keys, is excellent! Once you've updated the pathname logic, this will be perfect. Keep up the great work!
✨ 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
| return http.createServer((req, res) => { | ||
| const urlParams = new URL(req.url, `http://localhost:5701`); | ||
|
|
||
| const pathName = urlParams.pathname.split('/').slice(1); |
There was a problem hiding this comment.
The current logic for parsing pathname doesn't fully handle cases with multiple slashes (e.g., /a//b) or trailing slashes (e.g., /a/b/), which can result in empty strings in the final parts array. The requirement states that "doubled slashes should be ignored".
A more robust approach is to filter out empty strings after splitting the path:
const pathName = urlParams.pathname.split('/').filter(Boolean);This will correctly handle various slash combinations and produce a clean array of path segments as required.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
All core requirements for the HTTP server are fully met. Your implementation correctly parses the request URL, splits the path into segments (ignoring empty ones), and collects query parameters into an object. The JSON response structure matches the specification, and edge cases like doubled or trailing slashes are handled gracefully. The code is clean, robust, and demonstrates good use of modern JavaScript features. No changes are needed—great job! You can proceed to the next task.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.