Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clean URLs middleware with proper Content-Type headers and improv… #438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kenzycodex
Copy link

Clean URLs Middleware Enhancement

This PR adds a new middleware that provides clean URL routing for HTML files while maintaining proper HTTP headers and query parameter handling.

Features

  • Removes .html extensions from URLs (e.g., /about.html/about)
  • Preserves query parameters during redirects
  • Sets proper UTF-8 charset in Content-Type headers
  • Handles trailing slashes consistently
  • Maintains backward compatibility with direct .html requests
  • Properly handles URL-encoded characters

Implementation Details

  • Added middleware/clean-urls.js with comprehensive URL handling
  • Includes full test coverage in test/clean-urls.test.js
  • Adds Cache-Control headers for redirects
  • Handles edge cases (root path, missing files)

Testing

All tests pass and cover:

  • Non-HTML file handling
  • Query parameter preservation
  • URL encoding preservation
  • Trailing slash handling
  • Root path resolution
  • Direct .html requests

Breaking Changes

None. This is an opt-in middleware that maintains compatibility with existing behavior.

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.

1 participant