skip to Main Content

The linux app service is configured with a Node 18 LTS stack and a startup command that’s set to:

pm2 serve /home/site/wwwroot --no-daemon --spa

The --spa tag is supposed to make all routes fallback to index.html which is not the case when accessing an url directly, a 404 error is fired. But when using the root domain, the Angular routing works correctly.

2

Answers


  1. I have deployed the Angular app to Azure Linux App service.

    • In your deployed app, Configuration => General Settings => Startup Command, the start up command varies based on the type of deployment.
    • If you have deployed your App using Local Git then the Startup Command has to be
    pm2 serve /home/site/wwwroot --no-daemon --spa
    

    Locally , when we run the command ng build, dist folder will be created in the project root directory.

    My Configuration

    enter image description here

    how can we set fallback route or "default document" in a Linux based App Service ?

    The option to set Default Documents is available only for Windows App Service Plan.

    Thanks @Huw O. Roberts for the Default document script.

    For Linux App Service by default node.js app treats hostingstart.html as the default document. If we want to change the default document, use the below code in your app.js or index.js file.

      var options = {
            index: 'index.html'
        };
    

    Referenecs taken from tutorials

    Login or Signup to reply.
  2. When I deployed an Angular application on "Azure Linux App service" I experienced the same problem.
    I added this attribute to the angular route to ignore this issue.

    RouterModule.forRoot(AppRoutes, { useHash: true })
    

    You can get more details from this answer 404-error-angular

    We hope that Azure will provide a configuration to "Azure Linux App service" like what they did when deploy on "Azure Static Web Apps" by add "staticwebapp.config.json"

    You can find more details here 404-error-azure-static-web-app

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search