Heroku + node.js: I have a server that uses multiple ports. How can I get Heroku to distribute them?

Umm, I will try to be more clear.

On the application server that I wrote in node.js, I have an internal proxy for several ports:

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

I use the npm subdomain-router package for internal routing to a port, exposing the subdomains in the "front-end", which proxy back to these ports.
code demonstration: ( <some-app> clearly not the true name of the application)

 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 fine, although I cannot access it through <some-app>.herokuapp.com:8080 , but only through <some-app>.herokuapp.com and let the subdomain-router internal module make it magical.
In addition, I cannot access the sub-regions. When I try to access the api.<some-app>.herokuapp.com I get a No such app error page from heroku.

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

When I try to access my API by specifying the port in the URL (for example: <some-app>.herokuapp.com:8080 ), I get the following error in my browser (google chrome): ERR_CONNECTION_REFUSED .

My educated guess suggests that this may be due to the opening of ports in the hero, but I do not know how to do this (I tried googling ofc). <sh> This does not explain why I cannot access the subdomains.

Would thank any light shed on this issue.
I'm new to the hero and it really upsets.

Thanks!
Amit

+12
subdomain port deployment heroku
source share
2 answers

Well, after some research, I found that opening ports in Heroku is disabled and not allowed .

is to use subdomains and then in-app use a proxy module (e.g. subdomain-router , which I use).

BUT . Heroku does not allow the creation of subdomains in its domain, which means that your-app.herokuapp.com is fixed and cannot have subdomains.
In Heroku manuals, they require your own domain and dns provider to do this by creating A-alias (CNAME) in the dns table in your domain settings, which will reference your herokuapp application domain, and then use the heroku domains:add command to add your domain to the list of allowed sources.

Here you can read here . It provides all the necessary information.

Hope this helped someone.

+11
source share

I also found out about it today, I found out that if you start the port service in Heroku, you can still access it locally. It will not work for users, but this fixed my problem which led me to this question.

+1
source share

All Articles