App Service deployed successfully, but fails to find index.html

Michael 1 Reputation point
2022-01-29T00:41:30.407+00:00

I have a .Net API that hosts a Vue SPA. I previously deployed successfully to my Azure App Service, but after an update to the Vue app subsequent deployments all fail to correctly deploy the front end and I receive the error:

System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found

The API works, I can make requests with PostMan and they succeed.

Here is the Configure method from Startup.cs and here is the GitHub repo if you would like to look at other parts of the code. Let me know if other info would help.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CricketCreationsContext cricketCreationsContext)
        {
            cricketCreationsContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            if (env.IsProduction())
            {
                app.UseHttpsRedirection();
            }

            app.UseDefaultFiles();
            app.UseRouting();
            app.UseSpaStaticFiles();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseStaticFiles();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("/index.html");
            });

            app.UseSpa(spa =>
            {
                if (env.IsDevelopment())
                {
                    spa.Options.SourcePath = "clientapp";
                }
                else
                {
                    spa.Options.SourcePath = "clientapp/dist";
                }
            });
        }

After digging further. I've found that the SPA files are not being copied with the deployment. I tried to add this, but it didn't hel:

app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "clientapp")),
                RequestPath = "/clientapp",
            });

Thanks in advance for all your help!

Azure Stack Hub
Azure Stack Hub
An extension of Azure for running apps in an on-premises environment and delivering Azure services in a datacenter.
180 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,997 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ryan Hill 26,236 Reputation points Microsoft Employee
    2022-02-01T23:57:17.353+00:00

    Hi @Michael ,

    With regards to

    System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found

    You don't have an index.html in your wwwroot folder. But you said it initially worked but stopped after making a change. What was the change? When you browse to the app service file system, do you see the files from your client/dist folder?


  2. Vitaly Ivanov 1 Reputation point
    2022-11-11T14:02:21.97+00:00

    you need to add app.MapFallbackToFile("index.html"); after app.UseSpa()

    0 comments No comments