tower-rs / tower-rs/tower-http
Allow ServeDir to rewrite path to include .html
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 913
- Forks
- 231
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 8
Description
Feature Request
Motivation
Next.js Static Export results in a /out directory that looks something like
/out/index.html
/out/register.html
/out/404.html
This differs slightly from a traditional SPA where all routes would go to index.html, as a request to /register should use the register.html file.
There may be a way to accomplish what I'm asking, but I couldn't figure it out from the docs and/or examples.
I tried use ServeDir as so
let app = Router::new().nest_service("/", ServeDir::new("out"));
Going to / correctly returns the index page.
Going to /register.html correctly returns the register page.
But I want /register to also return the register page, but it returns 404
Proposal
For a given path without any extension, attempt to append .html. Similar to append_index_html_on_directories, but could have something such as append_html_on_directories where it would only append ".html" rather than "index.html" to the path.
Alternatives
Not sure of any.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ServeDir service and its append_index_html_on_directories documentation and examples. Determine how an extensionless request should resolve to the corresponding .html file, then verify that /register serves register.html while existing index and explicit .html behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100