-2

Im trying to start a nestJS app within an Azure App Service. The is being deployed via a DevOps pipeline. The build created a dist folder which I am deploying using zip deploy. The container seems to start ok, but I get 404 when browsing.

Container web##############_1_db5070dc for site web############# initialized successfully and is ready to serve requests.

Im starting the app using: pm2 serve /home/site/wwwroot/dist/ --no-daemon > app.log

It all looks good, other than the 404

Any help would be amazing

AjayKumar
  • 2,812
  • 1
  • 9
  • 28

1 Answers1

1

Just to highlight, the Node.js apps must be deployed with all the required NPM dependencies. The App Service deployment engine automatically runs npm install --production for you when you deploy a Git repository, or a Zip package with build automation enabled.

When you say starting the app using pm2 serve, I believe you have added the “Start file" (start command) section on app settings on Azure Portal.

For a custom start file use either of the supported extensions: .js file / PM2 file with the extension .json, .config.js, .yaml, or .yml

For Nestjs on Linux WebApp, try these flow:

  1. Navigate to the src/main.ts and change the port from 3000 to process.env.PORT
  2. Navigtate to the .gitignore and remove the dist from the compiled output section
  3. In the command line run "npm run build" this will trigger npm to run the build script in the package.json and produce a dist folder.
  4. Deploying the application via git/github should trigger the oryx build which will install the node modules needed to run the app
  5. In the portal, navigate to configuration and set the startup command to "node dist/main.js"

Then, check to see of the WebApp works fine.

In case, your using App Service on Windows, add a web.config file to the root of the application (Nestjs Web.config)

Kindly see this doc for more info Configure a Node.js app for Azure App Service

AjayKumar
  • 2,812
  • 1
  • 9
  • 28