Skip to content

feat: implement HTTP server with file handling and error responses#359

Open
adonch wants to merge 1 commit intomate-academy:masterfrom
adonch:develop
Open

feat: implement HTTP server with file handling and error responses#359
adonch wants to merge 1 commit intomate-academy:masterfrom
adonch:develop

Conversation

@adonch
Copy link
Copy Markdown

@adonch adonch commented Mar 27, 2026

  • Create a basic HTTP server that serves files from a public directory.
  • Handle invalid paths and provide appropriate HTTP status codes.
  • Ensure requests to /file/ prefix are processed correctly.

- Create a basic HTTP server that serves files from a public directory.
- Handle invalid paths and provide appropriate HTTP status codes.
- Ensure requests to /file/ prefix are processed correctly.
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 setting up the server and handling the routing for different file paths! The core logic for reading files from the public directory is working well.

However, changes are needed because all files are currently being served with a Content-Type of text/plain. This is a critical issue because it prevents web browsers from correctly rendering the content. For example, an HTML file will be displayed as plain text instead of a rendered webpage, and CSS files won't be applied as styles.

To fix this, you'll need to dynamically set the Content-Type header based on the requested file's extension. For instance, a file ending in .html should have a Content-Type of text/html, and a .css file should have text/css.


✨ 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

res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('File Not Found');
} else {
res.writeHead(200, { '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 hardcoded to text/plain. This will cause browsers to display HTML and CSS files as plain text instead of rendering them. Consider dynamically setting the Content-Type based on the requested file's extension (e.g., .html -> text/html).

Copy link
Copy Markdown

@vadiimvooo vadiimvooo left a comment

Choose a reason for hiding this comment

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

Well done

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