【问题标题】:Using Azure ZipDeploy, what port should my Node.js app listen on?使用 Azure ZipDeploy,我的 Node.js 应用程序应该监听哪个端口?
【发布时间】:2019-06-04 10:26:50
【问题描述】:

我有一个 GraphQL Node api 层,默认情况下侦听端口 3001。

当我使用 ZipDeploy 将应用程序部署到 Azure Web 应用程序时,我无法访问任何端点(例如 /graphql)。

我了解 Azure Web 应用仅侦听 80 或 443,但是当我将我的应用配置为侦听其中任何一个时出现错误。

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)

我需要在 Azure 中进行其他配置吗?

谢谢, 杰夫

【问题讨论】:

    标签: node.js azure-web-app-service


    【解决方案1】:

    如果您要部署到 Azure Web 应用程序,则只有端口 80443 是面向公众的。这映射到您的应用程序要侦听的特定端口,可通过process.env.PORT 检索。

    如果您同时在 Azure 和本地运行,则可以根据您在问题中对端口 3001 的引用,轻松管理您侦听的端口,如下所示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多