Skip to content

Solution#362

Open
KazymyrYan wants to merge 2 commits intomate-academy:masterfrom
KazymyrYan:develop
Open

Solution#362
KazymyrYan wants to merge 2 commits intomate-academy:masterfrom
KazymyrYan:develop

Conversation

@KazymyrYan
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 setting up the static file server and implementing the security check to prevent directory traversal! I'm requesting a couple of changes to meet all the task requirements. First, the route /file currently returns a text message instead of public/index.html as required. You can fix this by removing the special check for this route, as your existing logic already handles it. Second, the Content-Type header is hardcoded as text/html, which will cause issues with files like CSS. This needs to be set dynamically based on the file's extension. Addressing these two points will get your solution fully compliant. 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +11 to +16
if (url.pathname === '/file') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Please specify a file path after /file/.');

return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

According to the task description, a request to /file should return public/index.html. This block of code handles that case differently by returning a plain text message. The logic on line 25 is already set up to handle both /file and /file/ correctly, so this special check can be removed.

try {
const data = fs.readFileSync(fullPath);

res.writeHead(200, { 'Content-Type': 'text/html' });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Content-Type header is hardcoded as text/html. This means that other file types, like CSS or JavaScript, will not be correctly interpreted by the browser. The content type should be set dynamically based on the requested file's extension. You could create a simple map of extensions to MIME types or use an external library to handle this.

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 implementing the dynamic Content-Type header! This requires a small change before it can be approved. The server needs to serve public/index.html for requests to the /file route, but it's currently returning a plain text message. This is happening because of a specific if statement in src/createServer.js that handles this path separately. If you remove that conditional check, the rest of your code is already set up to handle this case correctly. You're very close to completing all the requirements!


✨ 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

Comment on lines +29 to +34
if (url.pathname === '/file') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Please specify a file path after /file/.');

return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

According to the requirements, a request to /file should return public/index.html. This block prevents that by sending a text response instead. If you remove this if statement, the logic that follows will correctly handle this case by defaulting to index.html.

Copy link
Copy Markdown

@2pasha 2pasha left a comment

Choose a reason for hiding this comment

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

lgtm 🔥

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.

3 participants