-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When using Microsoft.AspNetCore.SpaServices.Extensions in production, I'm getting this error intermittently. The weird thing is that the site is functioning correctly, and I can verify that the index.html file exists. Any ideas as to what might be causing this? I am unable to reproduce it at will.
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request. Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.
Startup.cs
Startup.ConfigureServices()
services.AddSpaStaticFiles(config =>
{
config.RootPath = "dist";
});Startup.Configure()
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.Use((context, next) =>
{
if (context.Request.Path.StartsWithSegments("/api"))
{
context.Response.StatusCode = 404;
return Task.CompletedTask;
}
return next();
});
app.UseSpaStaticFiles();
app.UseSpa(builder =>
{
if (env.IsDevelopment())
{
builder.UseProxyToSpaDevelopmentServer("http://127.0.0.1:5174");
}
});Expected Behavior
Expect no exception as the index.html file exists in the correct location.
Steps To Reproduce
Unable to reproduce on demand
Exceptions (if any)
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request. Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.b__1(HttpContext context, RequestDelegate next)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at MyProjectName.Startup.<>c.b__8_2(HttpContext context, Func`1 next) in /src/MyProjectName/Startup.cs:line 175
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
.NET Version
6.0.9
Anything else?
No response
