Skip to content

Solution#462

Open
SerhiyDmytruk wants to merge 1 commit intomate-academy:masterfrom
SerhiyDmytruk:develop
Open

Solution#462
SerhiyDmytruk wants to merge 1 commit intomate-academy:masterfrom
SerhiyDmytruk:develop

Conversation

@SerhiyDmytruk
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

Great job on this task! Your server correctly implements all the requirements, parsing the URL path and query parameters as expected. I am approving your solution.

I've left a few minor suggestions in the comments for future reference. For instance, you can make the path parsing more concise by using myURL.pathname.split('/').filter(p => p). I also noticed a small recurring typo (responce instead of response). These are not blockers, just tips to help you write even cleaner code. Keep up the great work!


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

Footnotes

  1. Rate AI review example

Comment on lines +10 to +14
const parts = req.url
.split('?')[0]
.replaceAll('//', '/')
.replaceAll('/', ',')
.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 multi-step string manipulation works, but there's a more standard and readable way to parse URL path parts. You could split the path by / and then filter out the resulting empty strings.

Since you're already creating a URL object on line 16, you can get the pathname from it and process it like this:

const myURL = new URL(req.url, 'http://localhost');
const parts = myURL.pathname.split('/').filter(p => p);

This would make the logic for getting parts much simpler.

const myURL = new URL(req.url, 'http://localhost');
const newSearchParams = new URLSearchParams(myURL.searchParams);

const responce = {};
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 have a small typo here and in a few other places (responce). The correct spelling is response.

Comment on lines +33 to +37
if (newSearchParams.size > 0) {
for (const [name, value] of newSearchParams) {
responce['query'][name] = 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.

This loop works perfectly fine. For future reference, there's a more concise way to achieve the same result using Object.fromEntries():

responce['query'] = Object.fromEntries(newSearchParams);

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