Skip to content

feat: implement HTTP server with request handling#468

Open
adonch wants to merge 3 commits intomate-academy:masterfrom
adonch:develop
Open

feat: implement HTTP server with request handling#468
adonch wants to merge 3 commits intomate-academy:masterfrom
adonch:develop

Conversation

@adonch
Copy link
Copy Markdown

@adonch adonch commented Mar 27, 2026

  • Add createServer function to handle incoming requests.
  • Parse URL and extract pathname and search parameters.
  • Return JSON response for valid requests and 404 for not found.

- Add createServer function to handle incoming requests.
- Parse URL and extract pathname and search parameters.
- Return JSON response for valid requests and 404 for not found.
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

Your server setup is on the right track, and you've correctly handled the query parameters. However, changes are needed because the URL path parsing doesn't meet a key requirement.

Currently, your code doesn't handle doubled slashes correctly. For example, a path like //hello results in ['', 'hello'] instead of the expected ['hello']. This is because splitting the path by / can create empty strings when there are consecutive or leading slashes.

To fix this, you should filter the array of path parts to remove any empty strings after you split the pathname. Once that's done, your solution will be perfect!


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

// Return instance of http.Server class
return http.createServer((req, res) => {
const url = new URL(req.url, `http://${req.headers.host}`);
const pathname = url.pathname.slice(1).split('/');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method of parsing the pathname does not correctly handle doubled slashes as required. For example, a path like //hello will result in ['', 'hello'] instead of the expected ['hello']. You'll need to filter out the empty strings that result from splitting a path with multiple slashes.

- Add checks for invalid paths using .. and // in the request URL.
- Return 404 status with appropriate messages for invalid paths.
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

You've made good progress here, and using the URL object is a great choice. However, this requires changes because the main requirement for handling URL paths with extra slashes is still not met. Currently, paths with leading, trailing, or doubled slashes (like /, /users/, or //users) produce an array with empty strings. The goal is to ignore these slashes completely. To fix this, you need to filter out any empty strings from the parts array after you split the pathname. A simple .filter(part => part) after your .split('/') call will do the trick. Once that's in place, your server should handle all path variations correctly!


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

// Return instance of http.Server class
return http.createServer((req, res) => {
const url = new URL(req.url, `http://${req.headers.host}`);
const pathname = url.pathname.slice(1).split('/');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a good step forward, but paths with a leading or trailing slash (like / or /users/) still produce an array with empty strings (e.g., [''] or ['users', '']). To meet the requirement of ignoring doubled/trailing/leading slashes, you'll need to filter these empty strings out of the pathname array after splitting the path.

- Removed redundant path validation checks.
- Streamlined response handling for valid requests.
- Improved readability of pathname processing.
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

Excellent work on this update! You've successfully implemented the feedback from the previous review, and the server now correctly handles URL paths with extra slashes. The code is clean, efficient, and meets all the specified requirements. This is a great submission, and I am approving it.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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