Get host and port for Heroku app

1.8k views Asked by At

I'm trying to get a Crossbar.io app running on Heroku. Crossbar.io requires you to put the app's host in a config file that's used to launch the app. I've tried the following:

  1. my-app-name.herokuapp.com: No dice. I imagine Heroku does some fancy redirection internally that prevents this from working.
  2. $HOSTNAME: running a script that outputs the HOSTNAME and using the result in the config file doesn't work either. The HOSTNAME is a GUID that contains no useful information.
  3. IP: I tried getting the external IP of the app, but no luck. The IP changes each time I start the app.

Is there an established way to do this on Heroku?

Also the config requires a port and Heroku seems to assign these dynamically. Any way to access the port as well (ideally before the app runs)

1

There are 1 answers

0
Huhwha On BEST ANSWER

For the host use 0.0.0.0. For the port number it's slightly more complicated...

When it creates a web dynamo Heroku sets a PORT environment variable with the dynamo's port. To set this in crossbar you need to create a script that reads that variable and writes it into your config wherever the port is requested. Then you make sure that the script returns 0 on exit and put the following in your Procfile:

web: ./your_config_helper_script && crossbar start

That runs your script first (which should get your config file ready) before running crossbar