简体   繁体   中英

Using Azure ZipDeploy, what port should my Node.js app listen on?

I have a GraphQL, Node api layer that by default, listens on port 3001.

When I deploy the app to an Azure Web App using ZipDeploy, I can't access any endpoints (eg /graphql).

I understand that Azure Web Apps only listen on 80 or 443, but I get an error when I configure my app to listen on either of those.

2019-06-04 10:09:40 [32minfo[39m: Running a GraphQL API server at 
http://localhost:443/graphql
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES :::443
    at Server.setupListenHandle [as _listen2] (net.js:1286:14)
    at listenInCluster (net.js:1334:12)
    at Server.listen (net.js:1421:7)

Is there something else in Azure I need to configure?

Thanks, Jeff

If you're deploying to an Azure Web App, only ports 80 and 443 are public-facing. This maps to a specific port for your app to listen to, retrievable via process.env.PORT .

And if you're running both in Azure and locally, you can easily manage which port you listen to, with something like this, based on your reference to port 3001 in your question:

var port = process.env.PORT || 3001;
server.listen(port);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM