feat: serve Vue SPA as static files from .NET API (PKG-01 #533)#556
feat: serve Vue SPA as static files from .NET API (PKG-01 #533)#556Chris0Jeky merged 3 commits intomainfrom
Conversation
Add UseDefaultFiles(), UseStaticFiles(), and MapFallbackToFile("index.html")
to PipelineConfiguration so the packaged .NET API can serve the built Vue SPA
from wwwroot/ without a separate web server. API and SignalR hub routes are
matched before the fallback and remain unaffected.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Code Review
This pull request configures the ASP.NET Core pipeline to serve a Vue SPA by adding static file middleware and a fallback route for client-side navigation. A security concern was raised regarding the middleware order: UseStaticFiles is currently placed before SecurityHeadersMiddleware, which prevents security headers from being applied to the SPA's static assets. It is recommended to move the security middleware earlier in the pipeline to ensure all responses are protected.
| app.UseDefaultFiles(); | ||
| app.UseStaticFiles(); |
There was a problem hiding this comment.
The current placement of the static files middleware can lead to security issues. The UseStaticFiles middleware can short-circuit the request pipeline, meaning any middleware registered after it will not run for static file requests.
Currently, SecurityHeadersMiddleware is registered after UseStaticFiles. This means important security headers like Content-Security-Policy, X-Frame-Options, and X-ContentType-Options will not be applied to the SPA's main index.html file or its assets (JS, CSS). This could expose your application to vulnerabilities like clickjacking or weaken its defense against XSS.
To ensure all responses receive these critical security headers, you should reorder the middleware pipeline. I recommend moving app.UseMiddleware<SecurityHeadersMiddleware>(); to before the app.UseDefaultFiles(); call. You might also consider moving app.UseMiddleware<CorrelationIdMiddleware>(); for better request tracing.
Move UseDefaultFiles()/UseStaticFiles() to after SecurityHeadersMiddleware so the OnStarting callback is registered before the pipeline short-circuits, ensuring CSP, X-Frame-Options, and other security headers are applied to SPA assets including index.html.
|
Self-review findings and fix applied: Issue found: Original placement of Fix applied (commit Remaining checks passed:
LGTM after fix. |
Issue AC specifies "SPA assets are served with appropriate cache headers". Vite-generated /assets/* files use content-hashed names so they can be cached indefinitely (max-age=31536000, immutable). All other files, including index.html, get no-cache to ensure users receive the latest version after each deployment.
Adversarial Review Pass 2Checks run: dotnet build (0 warnings, 0 errors), dotnet test (1,485 tests, 0 failures across all suites: Domain.Tests, Application.Tests, Api.Tests, Cli.Tests, Architecture.Tests) Findings:
Fixes applied:
Overall verdict: LGTM after fix. The middleware ordering is correct, security headers are properly applied to static file responses via the |
Summary
UseDefaultFiles(),UseStaticFiles(), andMapFallbackToFile("index.html")toPipelineConfiguration.cswwwroot/without a separate web server/api/*) and SignalR hubs (/hubs/*) are unaffected by the HTML fallbackCloses #533
Test plan
dotnet build Taskdeck.sln -c Releasepasseswwwroot/, navigating to the app root servesindex.html