0

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.

Mehdi Benmoha
  • 3,694
  • 3
  • 23
  • 43
  • Please share your `web.config` file from the deployed azure app `wwwroot` directory. – Harshitha Nov 14 '22 at 10:10
  • There's no `web.config` file, and it seems like by changing the stack to Node 18 LTS and switching the argument `--spa` to the beginning, something happened in the Azure backend, and it worked, in Terraform we can see a new attribute set to index.html : `default_documents = [ "index.html", ]` – Mehdi Benmoha Nov 14 '22 at 13:27
  • Yes,even you can add `Default documents` in Azure app configuration =>Default document section. – Harshitha Nov 14 '22 at 13:49
  • Can't find that section in my Linux based app service.. – Mehdi Benmoha Nov 14 '22 at 14:18
  • Default document option is available only for Azure Windows App Service. – Harshitha Nov 14 '22 at 15:10
  • we were able to set it for Linux app through terraform, if that's just delusional, do you know how can we set fallback route or "default document" in a Linux based App Service ? – Mehdi Benmoha Nov 14 '22 at 16:06

2 Answers2

0

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

Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • I really would have preferred an Azure abstraction as it's a PaaS service, isn't it ? rather than using a hand made express server.. Still, in my case I didn't need all of that just use the default document property in terraform. – Mehdi Benmoha Nov 21 '22 at 12:45
0

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

Ahmed Alnahas
  • 263
  • 1
  • 4