托管在Heroku上的Node.js可以在非标准端口上侦听吗? [英] Can I have node.js listen on a non-standard port when hosted on Heroku?

查看:136
本文介绍了托管在Heroku上的Node.js可以在非标准端口上侦听吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个node.js应用程序,并试着在Heroku上托管它。看起来,为了让我的应用程序可用于世界,我需要这样听:

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);

我希望我的应用程序在端口8080上侦听。我可以更改process.env.port的值吗?它似乎是某种反向代理,我可能无法控制。

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.

推荐答案

不。 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.

这篇关于托管在Heroku上的Node.js可以在非标准端口上侦听吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆