Skip to content

task#344

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

task#344
iryna-knyzh wants to merge 2 commits intomate-academy:masterfrom
iryna-knyzh:develop

Conversation

@iryna-knyzh
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 server and implementing the security measure to prevent directory traversal! Your code is well on its way. However, a couple of changes are needed to meet all the project requirements.

I am requesting changes based on two main issues:

  1. Incorrect handling of root file paths: According to the task, requests to /file and /file/ should serve the public/index.html file. Your current implementation returns a hint message instead. Please adjust the logic to handle these specific paths correctly.
  2. Hardcoded Content-Type header: The Content-Type is always set to text/html. This causes problems for other file types. For example, when the server serves main.css, the browser won't be able to apply the styles. This header should be set dynamically based on the requested file's extension.

Once these two issues are addressed, your server should be 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 +30 to +34
if (pathname === '/file' || pathname === '/file/') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');

return res.end('Use /file/pathToFile to load the file');
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, requests to /file and /file/ should return the public/index.html file. This implementation currently returns a hint message instead.

const file = await fsp.readFile(finalPath, 'utf-8');

res.statusCode = 200;
res.setHeader('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 is hardcoded to text/html. This will not work for other file types, like the main.css file from the requirements example. The browser won't be able to correctly interpret a CSS file served with this content type. Consider setting this header dynamically based on the file's extension.

@iryna-knyzh
Copy link
Copy Markdown
Author

@mateacademy-ai-mentor
If I make this changes I cant pass the tests

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

Hello! Thanks for your submission. You've done a great job with the server structure and especially the directory traversal protection.

However, a couple of changes are needed to meet the core requirements. The two main issues from the last review are still present:

  1. Root path handling: Requests to /file and /file/ should serve the public/index.html file, but they currently return a text hint. You'll need to modify your logic to treat these paths as a request for index.html.
  2. Dynamic Content-Type: The Content-Type header is hardcoded as text/html. This needs to be set dynamically based on the file extension (e.g., .css files should have a Content-Type of text/css). You can use path.extname() to get the extension and a switch statement to set the correct header.

Please address these two points. You're very close to completing the task!


✨ 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 +30 to +34
if (pathname === '/file' || pathname === '/file/') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');

return res.end('Use /file/pathToFile to load the file');
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 requirements, requests to /file or /file/ should serve the public/index.html file. This block currently returns a hint message. You'll need to modify this logic to read and return the content of index.html instead.

const file = await fsp.readFile(finalPath, 'utf-8');

res.statusCode = 200;
res.setHeader('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 here, which was pointed out in the last review. For the server to work correctly with different file types (like CSS), this header needs to be set dynamically based on the file extension. You can use the path.extname() method to determine the file type and set the appropriate Content-Type.

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 work on the server implementation! You've successfully met all the functional requirements, correctly handling different paths and dynamic content types.

I am approving your solution as an educational override so you can proceed, but it's important to improve your test suite to ensure everything works as expected. Your tests are currently missing a few key checks:

  • The test for the root path only covers /file. Please add a check for /file/ as well.
  • Your tests for valid files should also assert that the Content-Type header is correct (e.g., text/html for HTML files).
  • There is no test for paths that do not start with /file. Please add one to verify the server sends the correct hint and status code.

Strengthening your tests is a crucial skill, and it will make your solution much more robust. Keep up the excellent progress!


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

Footnotes

  1. Rate AI review example


describe('Other routes', () => {
it('should return hint message for routes not starting with /file/', async() => {
it('should return public/index.html for `/file/` and `/file`', async() => {
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 test's description mentions both /file/ and /file, but the code only tests the /file endpoint. To ensure full coverage of the requirements, you should add a test case for /file/ as well.

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