Skip to content

add task solution#351

Open
lublubuterbrodi wants to merge 3 commits intomate-academy:masterfrom
lublubuterbrodi:develop
Open

add task solution#351
lublubuterbrodi wants to merge 3 commits intomate-academy:masterfrom
lublubuterbrodi:develop

Conversation

@lublubuterbrodi
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 the overall structure of the server and implementing the security checks! However, there are a couple of key requirements that are not quite met. I am requesting changes to align the server's behavior with the task description.

Here are the main points to address:

  1. Incorrect handling of the /file route: In src/createServer.js, a request to /file should return public/index.html, but it currently returns a hint message. The logic should be updated to treat /file and /file/ identically.
  2. Incorrect response for other paths: For any request path that does not start with /file/, the server should return a hint message. Your implementation currently returns a 400 Bad request error for these cases.

Once you've updated the server logic, please also adjust the tests in tests/staticFilesServer.test.js to reflect the correct behavior. You're very close, and I look forward to seeing your updated 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 on lines +12 to +19
if (requestUrl === '/file') {
res.writeHead(200, {
'Content-Type': 'text/plain',
});
res.end('Use /file/<path-to-file> to load files from public 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.

According to the task description, a request to /file should return public/index.html. This implementation returns a hint message instead. The logic should be adjusted to treat /file the same way as /file/.

Comment on lines +21 to +28
if (!requestUrl.startsWith('/file/')) {
res.writeHead(400, {
'Content-Type': 'text/plain',
});
res.end('Bad request');

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 requirement states that if a request path does not start with /file/, the server should return a hint message. This block of code returns a 400 Bad request error instead.

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

I am requesting changes because a key requirement from the task description has not been met.

Great job on implementing the security checks and the overall structure of the server! However, the main issue from the previous review still needs to be addressed. The server does not correctly handle requests to the /file route.

  • Server Logic (src/createServer.js): A request to /file must return public/index.html, making its behavior identical to /file/. Currently, it returns a hint message. You can adjust your logic to handle both cases the same way.
  • Test (tests/staticFilesServer.test.js): Consequently, the test for the /file route is incorrect. It should be updated to expect the content of index.html instead of the hint message.

You're very close to completing this. Please update the server logic and the corresponding test to align with 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 +12 to +19
if (requestUrl === '/file') {
res.writeHead(200, {
'Content-Type': 'text/plain',
});
res.end('Use /file/<path-to-file> to load files from public 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.

This block is not handling the /file route correctly. According to the task requirements, a request to /file should return public/index.html, just like a request to /file/. This implementation returns a hint message instead. The behavior for /file and /file/ must be identical.

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 implementing the server logic! Your createServer.js file is excellent—it correctly handles all routes and includes the necessary security checks.

I am approving this solution as an educational override to help you progress. However, your test suite in tests/staticFilesServer.test.js is missing a couple of important checks. To make it complete, please add tests for the following scenarios:

  • A request to /file/ should return the content of index.html.
  • A request to a path that does not start with /file/ (like /) should return the hint message.

Adding these tests will ensure all requirements are fully covered and protect against future regressions. You've done great work here!


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

Footnotes

  1. Rate AI review example

Comment on lines +144 to 149
it('should return index.html for /file route', async () => {
const response = await axios.get(`${HOST}/file`);

expect(response.status).toBe(200);
expect(response.headers['content-type']).toBe('text/plain');
expect(response.data.length).toBeGreaterThan(0);
expect(response.data).toContain('<!DOCTYPE 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.

Great job on implementing the test for the /file route!

To make your test suite fully comprehensive according to the requirements, please consider adding two more test cases within this describe block:

  1. A test specifically for the /file/ route to confirm it also serves index.html.
  2. A test for a route that does not start with /file/ (for example, / or /some-other-route) to verify that the server returns the correct hint message.

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