Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
| const parts = req.url | ||
| .split('?')[0] | ||
| .replaceAll('//', '/') | ||
| .replaceAll('/', ',') | ||
| .split(','); |
There was a problem hiding this comment.
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 = {}; |
There was a problem hiding this comment.
You have a small typo here and in a few other places (responce). The correct spelling is response.
| if (newSearchParams.size > 0) { | ||
| for (const [name, value] of newSearchParams) { | ||
| responce['query'][name] = value; | ||
| } | ||
| } |
There was a problem hiding this comment.
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);
No description provided.