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

wai-app-static: serve HTML files without extension #999

Open
rniii opened this issue Aug 19, 2024 · 1 comment
Open

wai-app-static: serve HTML files without extension #999

rniii opened this issue Aug 19, 2024 · 1 comment

Comments

@rniii
Copy link

rniii commented Aug 19, 2024

Currently index.html files can be served by ssIndices, but it'd be useful if you could serve HTML files without an extension, e.g. posts/mypost.html -> posts/mypost

Alternatives

wai-extra's rewrite middleware could be used to add the .html extension on every request, but this would then break index.html files. Conditionally rewriting on whether the path ends with a / is also possible, but this would cause a lot of confusion and wouldn't match how frameworks usually serve static HTML

@rniii
Copy link
Author

rniii commented Aug 19, 2024

Not so sure how to implement this with the current code, but I got a custom lookup function to do this as a bit of a hack:

lookup pieces =
  case reverse pieces of
    name : pieces'
      | T.null $ T.dropWhile (/= '.') (fromPiece name) ->
          defaultLookup . reverse $
            unsafeToPiece (fromPiece name <> ".html") : pieces'
    _ -> defaultLookup pieces

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

No branches or pull requests

1 participant