My AspNetCore/React project works fine in the Development environment but as soon as I run it in any other environment I get 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.
The end of the startup.cs configure method looks like this
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
but since this is identical to the corresponding code in the app generated by dotnet new react I suppose something else is upsetting it.
The webserver does start and I can access Swagger pages. It's just the app proper that can't be found. Hacking the above code so that spa.UseReactDevelopmentServer(npmScript: "start");runs causes the app to be found for all environments (environment specific config is loaded) but served by the React dev server.
I would have said this line
spa.Options.SourcePath = "ClientApp";
was what governs the finding of /index.html and friends, but something is preventing them from being found.
What else I should look at?
I've seen this The SPA default page middleware could not return the default page but I don't think this is the problem I'm facing.
A search of the project reveals than there is only one file index.html and it is located in ClientApp/public. The Configure method starts like this
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days...
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();