Skip to content

Add SPA fallback support to YARP container image - #3006

Merged
MihaZupan merged 8 commits into
mainfrom
spafallback
Apr 8, 2026
Merged

MihaZupan merged 8 commits into
mainfrom
spafallback

Conversation

@davidfowl

@davidfowl davidfowl commented Apr 1, 2026 •

Copy link
Copy Markdown
Member

When YARP_ENABLE_STATIC_FILES is enabled, MapFallbackToFile("index.html") is registered after MapReverseProxy() so unmatched requests serve index.html for client-side routing (e.g., React Router, Vue Router).

Opt out: Set YARP_DISABLE_SPA_FALLBACK=true to disable the fallback.

Tested manually with a Vite + React SPA with react-router-dom:

GET / → 200, serves index.html ✅
GET /about (client route) → 200, SPA fallback to index.html ✅
GET /favicon.svg (static file) → 200, served directly ✅

When YARP_ENABLE_STATIC_FILES is enabled, MapFallbackToFile("index.html")
is registered after MapReverseProxy() so unmatched requests serve index.html
for client-side routing. Set YARP_DISABLE_SPA_FALLBACK=true to opt out.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
davidfowl and others added 5 commits April 1, 2026 09:18
Tests verify:
- SPA fallback returns index.html for unknown routes
- Static files are served directly
- SPA fallback can be disabled via YARP_DISABLE_SPA_FALLBACK
- Static files disabled means no fallback or file serving

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace all Environment.GetEnvironmentVariable calls with
IConfiguration lookups. Environment variables still work since
ASP.NET Core maps them to configuration automatically, but this
also enables JSON config and in-memory configuration for tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add tests for:
- Deep nested SPA routes (/app/settings/profile/edit)
- Missing file extensions return 404 (not fallback)
- Root path serves default document
- Missing index.html with empty webroot returns 404
- SPA fallback disabled still serves existing static files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify that:
- SPA fallback works alongside specific YARP routes (e.g. /api/*)
- A YARP catch-all route takes priority over the SPA fallback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use WebApplicationFactory to test the actual Program.cs pipeline
instead of duplicating the middleware configuration in tests.
Expose Program class via 'public partial class Program' for testability.
Replace LoadFromMemory with config-based YARP route setup to match
the real application's LoadFromConfig approach.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@MihaZupan MihaZupan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copilot AI changed the title Add SPA fallback support to YARP container image Use $(TestTFMs) and centralize package version for Application.Tests Apr 8, 2026
Copilot AI requested a review from MihaZupan April 8, 2026 11:17
@MihaZupan MihaZupan changed the title Use $(TestTFMs) and centralize package version for Application.Tests Add SPA fallback support to YARP container image Apr 8, 2026
@MihaZupan
MihaZupan enabled auto-merge (squash) April 8, 2026 11:46
@MihaZupan
MihaZupan merged commit 2517c4f into main Apr 8, 2026
7 checks passed
@MihaZupan
MihaZupan deleted the spafallback branch April 8, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants