Issue
I have an ASP.Net Core 6.0 application using Angular that runs perfectly fine locally in Visual Studio, but when I deploy it to AWS Serverless and navigate to '/', I get the below error.
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.\n\n at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.
When I manually browse to '/index.html', the Angular application loads, as expected.
I don't know if it could be related to my triggers. I had to define two separate ones, because "/{proxy+}" does not pick up "/". I was getting '{"message":"Missing Authentication Token"}' when I did not have the explicit "/" trigger.
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "ANY"
}
}
}
Here is my entry point:
public class LambdaEntryPoint : APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder.UseStartup<Startup>();
}
}
What am I missing that is preventing my application from loading the Angular application at '/index.html' when I navigate to '/'?
Solution
My application specifies the location of the Angular app with this line:
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
For some reason, I thought that this was only used for development in VS, and that at runtime, it would look for the files in "wwwroot", but that is not the case, and the application will only look in "ClientApp/dist".
I corrected the settings in my csproj file to copy the files to "ClientApp/dist", instead of "wwwroot" when deploying, and now I no longer get this error.
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
Answered By - Eric
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.