Running node-express application on Heroku with constant PORT - heroku

currently my nodejs application listens on process.env.PORT
This PORT is randomly set by heroku everytime heroku starts the dyno.
However I now have multiple applications that are going to use this express application. I can no longer have the PORT updating itself randomly.
I tried setting the PORT in config section of HEROKU. That did not set the PORT however.

Related

Problem deploying nginx on heroku in front of server on Go

I want to deploy to heroku nginx as a reverse proxy in front of my Go application.
I made a config file for nginx, but its samples presented here https://github.com/heroku/heroku-buildpack-nginx do not give an understanding of which port to specify in the proxy_pass directive to redirect to my application. These examples use unix socket listening instead of http.
upstream app_server {
server unix: /tmp/nginx.socket fail_timeout = 0;
}
But my application is running over http.
In addition, heroku uses random ports, which the application must retrieve from the PORT environment variable. However, now I have set this variable in the config for nginx. What port should my application run on now? If you specify your own port, this will not work, since heroku will say that the port is already busy.
I am completely discouraged by the difficulty of deploying a simple environment for my heroku application. None of the heroku instructions give a comprehensive understanding of how this can be done.
Please guide me on the right path.
P.S. For a couple of days of searching for an answer, I found only a lot of questions similar to mine and not a single answer.
Update.
I did as in this post Springboot application with nginx as proxy deploy on Heroku
But the author did not explain what she set in the APP_PORT variable. I set it to 3001 and got the same thing as here:
Nginx and Heroku. Serving Static Files

Why does this heroku-hosted java app return 404?

I have a .jar file that listens for requests and streams music (lavalink). When I run it locally on my own computer, I can make requests to it and everything works fine. However, when I move it to be hosted on heroku, trying to send a request to the app just results in nothing happening.
I am using "https://my-app-name.herokuapp.com" as the hostname to connect to, and the port I am using is the one that shows up in the logs:
Starting process with command java -Dserver.port=27955 -jar Lavalink.jar
^this one
Am I doing something wrong? Can Heroku maybe not find the java app? Do I need to provide a different hostname or port?
Turns out that Heroku always listens on port 80 for external requests and then routes the traffic to the port that shows up in the logs. Rewriting the config file (that the java app uses) during build to use the port that shows up in the logs seems to work.

How to point shared load balancer http/https port to specific port of my Jelastic Docker container

My app listens stuff on port 8082 (or whatever one).
I want to configure shared load balancer to route all requests from 443 port (HTTPS) to this port. As far as I understand, this is done by some Jelastic magic during container creation. So far so good, everything worked fine.
But after I've updated base image for my Docker app (from openjre-152 to openjre-171 or something like this) SLB stopped to re-route traffic to my app.
Is there way to change/setup this internal configuration manually without environment re-creation?
You should use JELASTIC_EXPOSE as written in docs, however, it's not clear that your traffic will be redirected and ssl-terminated by SLB.

How should I communicate with my server on Heroku if I don't know the port?

From what I have understood, Heroku assigns a port every time you deploy. I have an android app that is supposed to communicate with my server that I will deploy to Heroku.
But if I don't know the port, how do I make a POST call?
Does that mean Heroku is not suitable for this application?
I am using Java Spark, if that's relevant.
Your dyno internally uses a random port. Only the heroku router should communicate with that port.
You instead need to use the appname.herokuapp.com subdomain provided with your app, on port 80 or 443.
The router will then automatically forward the request to one of your dynos in random.
So yes, you can use heroku for your android app. Just make requests on the herokuapp.com subdomain like you would do anywhere else.

heroku different port for Rest service

I have a java application which exposes a port to receive data from outside. I'm wondering how to make heroku also expose this port? I now expose the port to 8170, when I tried to connect it, I always get couldn't connect to host error. I tried to change the $PORT variable, but it always says it fails to bind to port. Could anyone help me on this?
Many thanks in advance!
Per Can a Heroku app use different/multiple ports?, you can only use the default ports of 80 and 443 for apps on Heroku.
Changing $PORT is unlikely to help; this is the mechanism Heroku uses to tell your app what port to run on within the server; it then puts a proxy between the real network port and your application.
If you really, really must expose HTTP on a non-standard port, you'll need to find another deployment mechanism. My recommendation would be to try to update your REST client to not require a non-standard port.

Resources