herokuexpress-gateway

express-gateway on Heroku - {$PORT} binding error


I have deployed my express-gateway on Heroku, using env variables in this way in the gateway.config.yml file:

http:
  port: ${PORT:-8080}
  host: ${HOST:-localhost} 
https:
  port: ${PORT:-8080}
  host: ${HOST:-localhost}   
apiEndpoints:
  ....

Anyway Heroku keeps giving this error:

[EG:gateway] gateway http server listening on :::8080

State changed from starting to crashed
    
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

I have used the notation ${ENV_VAR_NAME:-DEFAULT} according to official documentation. Why Heroku tries to bind the 8080?

====== UPDATE

Just an out-of-topic tip, for who is going to use Heroku, here's how I get the redis url from the env vars.

      var redis_Url = process.env.REDIS_URL;
      var groups = /^redis:\/\/(.*?)\:(.+?)\@(.+?)\:(.+)$/gi.exec(redis_Url); 
      
      var nm = groups[1];
      var pasw = groups[2];
      var host = groups[3];
      var port = groups[4];
    
      process.env.REDIS_NM   = nm;
      process.env.REDIS_PASW = pasw;
      process.env.REDIS_HOST = host;
      process.env.REDIS_PORT = port;
      
      console.log('redis url   --> '+process.env.REDIS_URL);
      console.log('nm   --> '+process.env.REDIS_NM);
      console.log('pasw --> '+process.env.REDIS_PASW);
      console.log('host --> '+process.env.REDIS_HOST);
      console.log('port --> '+process.env.REDIS_PORT);


Solution

  • You should not make listen both the http and the https server on the same port, otherwise it's going to fail.

    Heroku provides its own router handling the SSL termination for you, so you can just remove the whole https section.