Skip to content

feat: add configurable index fallback for static files#534

Merged
iloveitaly merged 6 commits intorailwayapp:mainfrom
iloveitaly:static-workspace
Mar 28, 2026
Merged

feat: add configurable index fallback for static files#534
iloveitaly merged 6 commits intorailwayapp:mainfrom
iloveitaly:static-workspace

Conversation

@iloveitaly
Copy link
Copy Markdown
Collaborator

Motivation

Currently, the staticfile provider always routes non-existent paths back to the index page. While this behavior is ideal for Single Page Applications (SPAs), it prevents purely static sites (such as those generated by Astro) from correctly returning 404 errors for missing routes. These changes introduce a way for users to toggle this behavior based on their application's needs.

Description

  • Added an index_fallback configuration option to the Staticfile format to control SPA-style routing.
  • Updated the Caddyfile template to conditionally apply the routing fallback logic only when index_fallback is enabled.
  • Improved the robustness of root directory detection by trimming whitespace from environment variables and configuration values.
  • Introduced a new example directory and test cases to demonstrate and verify the index fallback functionality.

Screenshots / Test

  • Added examples/staticfile-index-fallback to demonstrate the new configuration.
  • Updated core provider tests and snapshots to cover the new routing logic.

Links

@iloveitaly iloveitaly force-pushed the static-workspace branch 2 times, most recently from 0a396cc to 512684a Compare March 27, 2026 17:22
- Fixes #railwayapp#533
- Introduce index_fallback option in Staticfile config to toggle SPA routing.
- Improve root directory detection by trimming whitespace from environment variables and configuration.
- Create a new example directory demonstrating the index_fallback configuration.
- Include a test case to verify that non-existent routes correctly serve index.html.

Generated-by: aiautocommit
@iloveitaly iloveitaly merged commit a891aeb into railwayapp:main Mar 28, 2026
225 checks passed
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

Successfully merging this pull request may close these issues.

Static Sites always returns never reach 404.

1 participant