当托管在 Heroku 上时,我可以让 node.js 监听非标准端口吗?
我正在构建一个 Node.js 应用程序,并尝试将其托管在 Heroku 上。看来,为了让我的应用程序可供全世界使用,我需要像这样监听:
app.listen(process.env.PORT || 3000);
我想让我的应用程序监听端口 8080。这在 Heroku 中可能吗?我可以更改 process.env.port 的值吗?这似乎是某种我可能无法控制的反向代理。
I'm building a node.js app and am experimenting with hosting it on Heroku. It seems that to make my app available to the world, I need to listen like this:
app.listen(process.env.PORT || 3000);
I'd like to have my app listen on port 8080. Is this possible in Heroku? Can I change the value of process.env.port? It seems to be some kind of reverse proxy that I might not have control over.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。Heroku 会告诉您的应用程序您的应用程序需要侦听哪个端口。 Heroku 和您的应用程序之间所需的接口是
PORT
环境变量:您的应用程序必须查找并使用它。除了 Heroku 告诉您的应用程序必须侦听的端口之外,您的应用程序无法侦听任何其他端口。 Heroku 尝试在该端口上打开到您的应用程序的 TCP 连接,如果自 Heroku 启动您的应用程序以来六十秒过去了,并且您的应用程序没有在该端口上侦听,Heroku 会认为您的应用程序已损坏并将其关闭。No. Heroku tells your application which port your application is required to listen on. The required interface between Heroku and your application is the
PORT
environment variable: your application must look for and use it. Your application is not able to listen on any other port except the port that Heroku tells your application it must listen on. Heroku tries to open a TCP connection to your application on that port and, if sixty seconds elapse since Heroku started your application and your application isn't listening on that port, Heroku figures your application is broken and shuts it down.