tower-rs / tower-rs/tower-http

Allow ServeDir to rewrite path to include .html

Open
#383 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request T-middleware
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.