Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve local and heroku application hostname outside a request

I have to configure one of the module in my application and give it a specific URL, based on the hostname. Something like http://localhost locally and http://myapp.herokuapp.com. I know I can just hardcode the value depending on NODE_ENV, or even store it as an environment value and use process.env.CUSTOMVAR_HOSTNAME. But somehow it feels wrong, since myapp is already configured in the Heroku admin panel. And I can't use request.headers.host since the module configuration happens at the start of the application, before any request can be handled.

Is there a way to retrieve the Heroku application name from the code ? Or from an environment variable ? I want my code to stay the same whether I'm executing code locally or on Heroku (or any other place actually).

like image 546
DjebbZ Avatar asked Oct 16 '12 00:10

DjebbZ


1 Answers

I didn't find any way, so I created a local variable hostname based on NODE_ENV (development or production) with the proper hostname value.

like image 115
DjebbZ Avatar answered Nov 16 '22 02:11

DjebbZ