Skip to content

Solution#374

Open
Artemida1609 wants to merge 3 commits into
mate-academy:masterfrom
Artemida1609:develop
Open

Solution#374
Artemida1609 wants to merge 3 commits into
mate-academy:masterfrom
Artemida1609:develop

Conversation

@Artemida1609
Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings May 10, 2026 19:06
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

Your implementation has critical gaps that must be addressed before approval. First, the Content-Type header is always set to text/plain, but the requirements explicitly state that .html files should return text/html and .css files should return text/css. Use path.extname() to determine the correct MIME type based on file extension. Second, there's no explicit check for the ../ substring in the pathname - the requirements specifically require returning a 400 status when ../ is detected in the pathname itself. Add a simple check like if (pathname.includes('../')) that returns a 400 response before any path processing occurs. Additionally, when the pathname is /file/ (with trailing slash), ensure it falls back to serving index.html from the public folder rather than attempting to read the directory itself. These corrections are essential to meet the task specifications.


✨ 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 thread src/createServer.js Outdated
Comment on lines +62 to +63
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
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 always set to text/plain. According to requirements, it should be text/html for .html files and text/css for .css files. Consider determining the content type based on the file extension.

Comment thread src/createServer.js
Comment on lines +36 to +50

const relativePath = fileName.replace('/file/', '');

const publicDir = path.resolve('./public');
const resolvedPath = path.resolve(`./public/${relativePath}`);

if (
!resolvedPath.startsWith(publicDir + path.sep) &&
resolvedPath !== publicDir
) {
res.statusCode = 400;
res.setHeader('Content-Type', 'text/plain');
res.end("You can't go outside /file folder");

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.

The requirements specify that if pathname contains ../ it should return 400 status. Currently there's no explicit check for ../ substring. The path traversal check handles security, but the explicit requirement is to detect ../ in the pathname itself.

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

Your implementation is close to complete but has one critical issue remaining. When the pathname is /file/ (with a trailing slash), the relativePath variable becomes an empty string, causing the server to attempt reading ./public/ which fails and returns a 404. According to the requirements, this should serve public/index.html instead. Add a fallback check before the fs.readFile call, such as: const fileToRead = relativePath || 'index.html'; and use this variable for the file path. All other requirements pass, including Content-Type handling and ../ security checks, so you're very close to a working solution.


✨ 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 thread src/createServer.js

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.

When pathname is /file/ (with trailing slash), relativePath becomes empty string. The code then tries to read ./public/ which fails. According to requirements, it should serve public/index.html instead. Add a check like: if (!relativePath) { relativePath = 'index.html'; } before the fs.readFile call.

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

This is an educational approval to help you progress while learning. You've done an excellent job implementing the path traversal and double slash security checks, as well as the file serving logic for /file/ requests. There's one remaining bug to fix: when serving /file/, the Content-Type defaults to text/plain because path.extname('') returns an empty string. The suggested fix is to add a fallback that checks if fileToRead === 'index.html' and returns 'text/html', or use path.extname(fileToRead) to derive the extension from the resolved filename instead of the empty relativePath. Once you address this small issue, your implementation will be complete!


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

Footnotes

  1. Rate AI review example

Comment thread src/createServer.js
Comment on lines +69 to +74

const ext = path.extname(relativePath);
const contentTypes = {
'.html': 'text/html',
'.css': 'text/css',
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When relativePath is empty (for /file/ requests), path.extname('') returns an empty string, causing contentTypes[''] to be undefined and defaulting to text/plain. This should be text/html since we're serving index.html. Add a fallback: const contentType = contentTypes[ext] || (fileToRead === 'index.html' ? 'text/html' : 'text/plain');

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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