tower-http icon indicating copy to clipboard operation
tower-http copied to clipboard

Allow ServeDir to rewrite path to include .html

Open jdukewich opened this issue 2 years ago • 1 comments

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.

jdukewich avatar Jul 08 '23 20:07 jdukewich