Dustin
Dustin

Reputation: 735

Angular CLI app not running when deploying to Linux App Service

I'm trying to deploy an Angular CLI app to Azure App Service on Linux OS, using Azure Dev Ops - but no success. I get Image 1. No error in the server or application logs.

Image 1

This is what I done so far:

  1. Built the Angular CLI app using DevOps Build and placed the resulted "dist" folder to the "drop" folder. See below (Image 2) the tasks that compose my build. This is working fine and creating the expected files.

Image 2

  1. Created a release in DevOps, deploying all the dist files in the wwwroot folder in the Azure App Service in Linux. Shown below are both, the wwwroot folder (left) and my local dist folder (right) after I run a ng build --prod.

Image 3

I have the suspicion that I need to kickstart the angular by feeding some time of command when doing the deployment. I have tried running "ng serve --host 0.0.0.0" but that didn't work.

Upvotes: 4

Views: 3754

Answers (7)

Dave Skender
Dave Skender

Reputation: 621

Check the Azure App Service > Linux section on this page. Essentially, you have to serve the app.

Add npx serve -s in the App Service Configuration > General Settings > Startup Command

enter image description here

In addition to the Azure Web App setting (above), you can also execute the startup after a deployment. If you are using Azure Pipelines, you'd kick it off with something like:

- task: AzureRmWebAppDeployment@4
  displayName: 'Deploy website'
  inputs:
    azureSubscription: '[your Azure subscription]'
    appType: webAppLinux
    WebAppName: '[your Azure web app]'
    packageForLinux: '[artifacts]/package.zip'
    StartupCommand: 'npx serve -s'

2023 UPDATE: you no longer need to configure this with a ecoysystem.config.js PM2 file in the root directory, with this inside as originally answered.

module.exports = {
    apps: [
        {
            script: "npx serve -s"
        }
    ]
};

Old reference: https://burkeholland.github.io/posts/static-site-azure

Upvotes: 9

Shivinder Singh
Shivinder Singh

Reputation: 151

I had the same problem on Azure App Service with Linux and Node, solved it using below startup command

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

Snapshot from my DevOps pipeline

Upvotes: 0

sunil
sunil

Reputation: 6614

I had to give the npx serve -s as the startup commandenter image description here

Then set the Runtime Stack with node framework 10.16 (NODE|10.16). See belowenter image description here

Then everything started working.

Upvotes: 4

Thomas Weglinski
Thomas Weglinski

Reputation: 1094

When using Linux App Service container, you may also select PHP stack containing Apache2 Server. Since, Angular files are static ones (JS, CSS, HTML), so you just need some web server to serve this content.

Example configuration: enter image description here

Upvotes: 1

JM Tee
JM Tee

Reputation: 121

If you still want to use App Service - Web App you can just the Windows OS instead of Linux.

Here are the parameters I Used:

Since the output of building angular is a static web app, IIS will serve the site right away.

Upvotes: 1

Dustin
Dustin

Reputation: 735

There is a subtle and big difference between the Linux and Windows App service: IIS - which in Windows is actively looking to serve any app, whereas in Linux you have to spin up something on your own to serve it - Express for example.

After some research I discovered that I don't need a full App service dedicated to run a static app (such as Angular or React). It can be done just as efficiently and much cheaper with something like Storage. -> https://code.visualstudio.com/tutorials/static-website/getting-started

Upvotes: 0

Remco Brilstra
Remco Brilstra

Reputation: 828

If you look at the default 'Deploy Node.js App to Azure App Service' release template, it uses the 'Deploy Azure App Service' task and adds the following commands to the task. this might help you out.

enter image description here

Upvotes: 0

Related Questions