Heroku + node.js:我有一个使用多个端口的服务器。如何让Heroku分配? [英] Heroku + node.js: I have a server which uses multiple ports. How can I get Heroku to allocate them?

查看:309
本文介绍了Heroku + node.js:我有一个使用多个端口的服务器。如何让Heroku分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在应用程序服务器中,我已经编写了node.js,我有多个端口的内部代理:




  • 在我的 8080 端口我有我的 rest api

  • 在我的 3000 端口我有我的推送服务器和聊天



我使用npm软件包子域路由器,用于内部路由到端口,将前端中的子域暴露给这些端口。

代码演示:



b



$ b

  require('subdomain-router')
({
host:'< some-app> .herokuapp.com',
subdomains:
{
'':8080,//< some-app> .herokuapp.com< => :: 8080 - WORKS--
'api':8080,/ / api。< some-app> herokuapp.com< => :: 8080
'chat':3000,//聊天。< some-app> .herokuapp.com< => :: 3000
'push':3000 // push。< some-app> .herokuapp.com< => :: 3000
}
})。listen(process.env.PORT || 5000);

尽管我无法通过< some-应用> .herokuapp.com:8080 ,但只能通过< some-app> .herokuapp.com 并让内部 subdomain-router 模块做它的魔法。

此外,我无法访问子域。尝试访问 api。< some-app> .herokuapp.com 我得到没有这样的应用程序错误页面



TL; DR 访问< some-app> .herokuapp.com 作品(重定向到我的API的 / v1 路径),但无法访问< some-app> .herokuapp.com:8080 < some-app> .herokuapp.com:3000 聊天。< some-app> .herokuapp.com



当尝试通过指定url中的端口访问我的API(如下: ; some-app> .herokuapp.com:8080 ),我的浏览器中出现以下错误(Google Chrome): ERR_CONNECTION_REFUSED



我有经验的猜测表示这可能与英雄中的开放端口有关,但我有没有线索如何做(尝试googling ofc)。

这不解释为什么我无法访问子域名。



会感激一下















Amit

解决方案

在做了一些研究之后,我发现Heroku的开放端口是 >和不允许



唯一方法是使用子域然后在应用程序中使用我使用的代理模块(例如 subdomain-router )。



但是 - Heroku不允许您在其域中创建子域,这意味着 your-app.herokuapp.com 是固定的,不能子域。

在Heroku手册中,他们要求您拥有自己的域和dns提供商,通过在域设置中的dns表中创建一个A-alias(CNAME)来执行此操作,即将引用您的应用程序herokuapp域,然后使用命令 heroku域:添加添加您的dom ain到允许的起始列表。



您可以阅读更多此处。它提供了您需要的所有信息。



希望帮助一些。


Umm I'll try to be more clear..

In an application server I have written in node.js, I have inner-proxy for multiple ports:

  • in my 8080 port I have my rest api.
  • in my 3000 port I have my push server and chat.

I use the npm package subdomain-router for inner-routing to the port, exposing sub-domains in the 'front-end' which proxy back to those ports.
code demonstration: (<some-app> is not the real name of the app obviously)

require('subdomain-router')
({
  host: '<some-app>.herokuapp.com',
  subdomains:
  {
    '': 8080,   // <some-app>.herokuapp.com <=> ::8080   --WORKS--
    'api': 8080,  // api.<some-app>.herokuapp.com <=> ::8080
    'chat': 3000, // chat.<some-app>.herokuapp.com <=> ::3000
    'push': 3000  // push.<some-app>.herokuapp.com <=> ::3000
  }
}).listen(process.env.PORT || 5000);

The API works great, though I cannot access it through <some-app>.herokuapp.com:8080, but only through <some-app>.herokuapp.com and let the inner subdomain-router module do it's magic.
Also, I can't access the subdomains. When trying to access api.<some-app>.herokuapp.com I get No such app error page from heroku.

TL;DR accessing <some-app>.herokuapp.com works (redirects to /v1 path for my API), but unable to access <some-app>.herokuapp.com:8080, <some-app>.herokuapp.com:3000 or chat.<some-app>.herokuapp.com.

When trying to access my API by specifying the port in the url (like this: <some-app>.herokuapp.com:8080), I get the following error in my browser (google chrome): ERR_CONNECTION_REFUSED.

My educated guess says that it might be something related to opening ports in heroku, but I have no clue on how to do it (tried googling ofc).
It doesn't explain why I cannot access the sub-domains though.

Would appreciate any light shed on this issue.
I'm new to heroku and it's getting really frustrating.

Thanks!
Amit

解决方案

Okay, after doing some research I've found out that opening ports in Heroku is disabled and not allowed.

The only way around this is to use sub-domains and then in-app to use a proxy module (like subdomain-router which I use).

BUT - Heroku don't let you create sub-domains on their domain, meaning that your-app.herokuapp.com is fixed and cannot have sub-domains.
In Heroku manuals, they demand you to have your own domain and dns provider to do such thing, by creating an A-alias (CNAME) in the dns table in your domain settings, that will refer to your app herokuapp domain, and then using the command heroku domains:add to add your domain to the allowed origin list.

You can read more here. It provides all the info you need.

Hope it helped some.

这篇关于Heroku + node.js:我有一个使用多个端口的服务器。如何让Heroku分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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