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

feat(http): add cleanUrls option to serveDir #6231

Closed
wants to merge 1 commit into from

Conversation

lowlighter
Copy link
Contributor

@lowlighter lowlighter commented Dec 4, 2024

This PR introduces a new cleanUrls option to serveDir function

It is inspired from a common pattern where you don't have to specify the html extension to serve a page.
(e.g. deno.com/blog, github.com/denoland/std, ..., some hosters such as Vercel also propose a similar feature)

Considerations:

  • Only .html is handled by this new option, for more advanced usage user would need to use their own routing
    • The reasoning for what it'd be supported natively by std is that it's a really common use case, and it's actually not that easy to get a simple workaround (e.g. if you use route(request), as Request are immutable you'll need to do some shenanigans to trim extensions, catch the 404 to retry with it, etc.)
    • It'd be an extremely nice QOL and since it's gated behind an option would not be a breaking change and would not hinder performances of existing apps
  • If the path without extension "shadows" another file or directory, the latter takes precedences over the otherwise cleaned url aliased file

Closes #6232

@github-actions github-actions bot added the http label Dec 4, 2024
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.51%. Comparing base (b1b8279) to head (857c391).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6231      +/-   ##
==========================================
- Coverage   96.52%   96.51%   -0.01%     
==========================================
  Files         534      534              
  Lines       40976    40986      +10     
  Branches     6134     6138       +4     
==========================================
+ Hits        39551    39559       +8     
- Misses       1383     1385       +2     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lowlighter
Copy link
Contributor Author

I'm closing it for now, but I still think this patch would be a nice QOL, especially since it doesn't have that much maintenance/overhead, but this may need further discussion as pointed on the discord server since opinions seems to be diverging.


Feedback from the discord:

It's common as a "framework feature", but for file server (like apache) you usually need either rewriting urls or set the default mime type to text/html

A workaround is to change the file structure to use folder + index.html instead but although it works it makes you change the way you organize file rather than your code (which shouldn't be, the file structure may be required to be a certain way depending on your use case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal(http): add cleanUrls option to serveDir
1 participant