-
Notifications
You must be signed in to change notification settings - Fork 9.9k
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The SPA default page middleware could not return the default page '/index.html' in production application #5223
Comments
Do angular output directory and specified path in <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="your\output\path\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target> |
I am setting the RootPath to the Angular dist folder: services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
}); And here is what's in my .csproj file: <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<!-- Set this to true if you enable server-side prerendering -->
<BuildServerSideRenderer>false</BuildServerSideRenderer>
</PropertyGroup>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target> I'm wondering if my problem is that I still have the SSR build instructions in the csproj even though SSR is not enabled, and dist-server does not exist..? |
SSR isn't the problem. You should set path in app.UseSpaStaticFiles();
app.UseSpa(configuration => { /*spa.Options.SourcePath = "ClientApp";*/ });
|
Sorry - not sure if you saw my edit, but I was in fact setting the RootPath correctly, I was just looking in the wrong place. :) I will try removing the SourcePath setting, however, I'm fairly certain this configuration came with the dotnet new angular template. What is the SourcePath setting used for and why shouldn't it be set? |
This is used to determine the folder where package.json scripts should be executed. app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
spa.UseSpaPrerendering(options =>
{
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
options.BootModuleBuilder = env.IsDevelopment()
? new AngularCliBuilder(npmScript: "build:ssr")
: null;
options.ExcludeUrls = new[] { "/sockjs-node" };
});
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
}); |
Thanks - I am using a proxy: spa.UseProxyToSpaDevelopmentServer("https://localhost:4200"); So sounds like I probably don't need the SourcePath setting. That said - are you saying the SourcePath setting is the cause of the errors in my production environment? |
No, |
I think maybe you aren't seeing the edits I made to my original response. I am setting the RootPath as suggested. (Maybe try refreshing the this Github page to ensure you are seeing the latest content). |
Now I see it. Can you show what's inside of |
Not much... Will of course remove the SourcePath setting since it's not needed, but this is what is currently in production: app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("https://localhost:4200");
}
}); |
Is index.html present after build in ClientApp/dist? I'd try to remove node_modules and install again, remove |
Index.html is present in clientapp/dist, otherwise the application wouldn't function at all - that is what is confusing about the error message. The error is being logged in a production application that seems to working fine. I will try removing the node_modules folder locally, and then rebuild and republish and see if that makes a difference. What makes you think that will resolve the error? |
Removing the node_modules folder and republishing did not solve the issue - still seeing quite a few of these errors logged on the production server. Any idea why that would be? |
I'm seeing the same issue as @danobri on a production site that appears to be working fine otherwise. The exceptions are intermittent, but persistent. I'm using the Angular spa template pretty much straight away with SSR enabled. |
It's an IIS Default Document issue. Just add the following to your web.config:
|
I have this same issue in production - using SPA for react. |
So, it was our vulnerability scanner that caused the exceptions to be generated. This means I can now reproduce it by scanning the IP this core app is installed on. I tried the Any ideas @SteveSandersonMS ? |
I'm also getting this error randomly in a couple of production sites that work just fine. ASP.NET Core 2.1, using React 16 in the front end. Below are the relevant parts of my Startup class. I get these notifications at off hours so it might be some scanner. Nothing critical but I'd love to solve it. Any help appreciated. Thanks!
|
This happened to my Azure App Service. All I had to do was to restart the service. Worked like charm. |
check angular.json file use "outputPath": "dist", And Startup file services.AddSpaStaticFiles(configuration => |
My case is a reactjs app. Also, restarting the service does not help. The service is not down. It is a error caused by requests from vulnerability scanners (or from systems trying to exploit the vulnerability) |
I can't even get a Seems like there is definitely a bug in the building process of the spa somewhere? |
@ryanbrandenburg / @mkArtakMSFT - any ideas? |
So the reason we're getting this is someone is trying to POST AND OPTIONS to /index.html not GET. Which causes this error message and causes a 500 error. Of course of Azure/IIS sees too many errors in too short a time it tries and recycles the app. the problem is that it's doing it over and over again which causes everything in that App Service Plan to crash. :< How do we properly handle this without the site throwing a 500 error? Note that this only happens in production, not development and as far as I can tell there is no way to handle this error with your own route. This is a major DOS attack vector in spa services that needs to be fixed ASAP. |
Would be nice if an error wasn't the default behavior. I was able to prevent the exceptions using a rewrite rule in my web.config.
|
I also had this issue what I did is use the rewrite middleware by doing the below.
|
I would really like to see the root of this problem solved. We have a .net core 2.1 app with the latest React version, no web config since we are using json files for environment variables. We are randomly getting this error several times at once. Most of the time it's fine and then randomly it will happen a dozen times. The redirect seems to just be a work around and not solve the root issue. |
Anyone has got a solution for this? |
Seems like these javascript services are unsupported? |
You seem to have the solution, nice way to ask for help ? what you need to understand is that your production environment issues cannot be solved by looking at the source code. you should be mapping the content of your publish folder which is at following path "angular12/WebAPI with Angular/WebAPI with Angular/bin/Release/net5.0/publish/" correctly under iis. If not then you need to read the link i have shared earlier and click on iis. |
Mate I did ask for help nicely, read my first post again. What's your problem? If you don't want to help that's fine. Been stuck on this for a while. I just hosted the server and client seperately and it works fine. I think that's the way to go. Thanks for responding anyway! |
my bad, you were prompting suggestion to the person who was trying to help you, it was sort of distracting. anyways good to know your problem is solved. i would still try and host server and client together, let's try again ? the only files that really has any say on the hosted environment is startup.cs and appsetting file and i notice one piece of code that is not consistent in the startup.cs file the code on line no. 52 should point to your published folder of angular - this is correct once this is corrected, try publishing again from step 1 to z It will be easy to diagnose the issue if you can share your hosted environment configuration. cheers. |
Sorry bro all good. I did that this, though the output path when published is ClientApp/dist. Where is the hosted environment configuration? I appreciate your help. I just get a white screen when pointed to the correct location: |
i need to see your published structure and its environment and configuration. I thought you were using iis please confirm, since the error file appears to be of kestrel. do you want to take this offline ? once sorted we can publish the solution here on git. |
Ok add me on Skype, rlm042. |
In VS 2022 with .Net Core 6 the standard ASP.Net Angular project template does not return index.html at all in Production mode.
PS. But it also requires changing the SPA deployment folder from wwwroot to ClientApp/dist (as it was in ASP.Net Core 3.1 template): |
Finally, I figured out this framework bug's root cause and how to work around it. You work around it by fixing another bug that you may not even realize is in your code. The other bug, and how to fix it (and thus work around the framework bug), are described here. |
I've used the following middleware, that check if allowed method is used before passing control to the Spa:
And then instead of app.UseSpa in Configure call app.UseGuardedSpa |
Thank you @Redart98 This is a huge gaping DOS hole in the .net core SPA framework. Yes, it makes sense to redirect routes to the SPA so it can handle routing on the front end, but I'm getting POST requests to index.html that are being redirected to the SPA middleware. It makes no sense. |
Thanks for contacting us. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I am getting error as below: Do you have any solution for that? |
I have this issue too with ASP.NET Core 6 and Microsoft.AspNetCore.SpaServices.Extensions with version 6.0.22 referenced in .csproj. |
I have an ASP.Net Core / Angular 5 application that is logging errors to the Windows Event Log in our production environment. The following error is getting logged frequently but intermittently in production, and I have no idea why. The application is definitely in production mode, has been published, and is functioning.
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.
AFAIK no users are experiencing a problem with the site when these errors occur. Any idea why these errors are being thrown, and whether there is in fact a problem that needs to be addressed?
The text was updated successfully, but these errors were encountered: