Conversation
raulriato
left a comment
There was a problem hiding this comment.
You've done a good job. Just need a few changes
| @@ -1,9 +1,24 @@ | |||
| /* eslint-disable no-console */ | |||
There was a problem hiding this comment.
It's not good to disable the eslint rules on your project.
| /* Write your code here */ | ||
| // Return instance of http.Server class | ||
| return http.createServer((req, res) => { | ||
| const url = new URL(req.url, `http://${req.headers.host}`); |
There was a problem hiding this comment.
You shoul use a try/catch to prevent your app from crashing if the new Url() doesn't work as expected
|
|
||
| const urlParams = { | ||
| parts: url.pathname | ||
| ? url.pathname.split('/').filter((pathname) => pathname !== '') |
There was a problem hiding this comment.
You don't need this ternary operator, since the pathname is always truthy in Url class
| ? url.pathname.split('/').filter((pathname) => pathname !== '') | ||
| : [], | ||
| query: url.searchParams | ||
| ? Object.fromEntries(url.searchParams.entries()) |
There was a problem hiding this comment.
You don't need this ternary operator, since the searchParams is always truthy in Url class
| : {}, | ||
| }; | ||
|
|
||
| res.setHeader('Content-Type', 'application/json'); |
There was a problem hiding this comment.
Your code does not specify the status code for the response. Even though the default status code is 200, you should make it explicit here.
res.writeHead(200, { 'Content-Type': 'application/json' });
No description provided.