Home > OS >  NodeJs Puppeteer on Azure App Services fails to run
NodeJs Puppeteer on Azure App Services fails to run

Time:11-27

I've wrote a simple NodeJs (ExpressJs) server that uses Puppeteer to generate PDF files on JSON data being passed to it. While locally everything is working like charm, I'm struggling to run this server on Azure App Services. I've created a Resource group, within it I've created an App Servces instance (running on Linux) that is connected to my repo at Azure DevOps (via the Deployment Center).

My server has two endpoints:

  1. / - returns a JSON - { status: "ok" }. I'm using this to validate the running server instance.
  2. /generate-pdf - uses the Puppeteer to generate and return a PDF file.

After successfully starting the App Service instance I'm able to access the "/" route and get a valid response but upon accessing the "/generate-pdf" route the result is "502 - Bad Gateway".

  1. Does my instance require some additional configuration that I haven't done?
  2. Does App Services can not run Puppeteer? Perhaps there is a different service on Azure that I need to use?
  3. Is there a way to automate the process via the Azure DevOps pipeline or release?

Any questions/thoughts/FAQs are more than welcomed. Thanks =)

CodePudding user response:

I'm answering my own question: as was mentioned here https://stackoverflow.com... the Azure App Services does not allow the use of GDI (which is required by Chrome) regardless if you're using Linux or Windows based system. The solution was to put the NodeJs application into a Docker container and manually install Chrome. Once you have a container - just upload it to the Azure App Services and viola!

  • By default App Servies exposes 80 and 443 ports, so if your application listens on a different port be sure to specify it via the WEBSITES_PORT environment variable.
  • In my case, I had to upload the Docker image to the Docker hub but you can also set up a pipeline to automate the process.
  • I've built the Docker image on my M1 Pro and it led to some arch issues when the container was uploaded to Azure. Be sure to add the --platform linux/amd64 in the image-building step if you're building for Linux.
  • Related