Repository navigation
Add SPA fallback support to YARP container image - #3006
Merged
Merged
Conversation
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>
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
approved these changes
Apr 8, 2026
…ject Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/cf05ed2e-8fb2-4f3c-b1bb-28b2d94fd468 Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
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
Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/430bcb41-38b7-4f4c-8568-328c9f796af7 Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ✅