How can I detect Heroku's environment?

前端 未结 7 1668
Happy的楠姐
Happy的楠姐 2020-12-24 05:40

I have a Django webapp, and I\'d like to check if it\'s running on the Heroku stack (for conditional enabling of debugging, etc.) Is there any simple way to do this? An envi

7条回答
  •  旧时难觅i
    2020-12-24 06:12

    The most reliable way would be to set an environment variable as above. If that's not possible, there are a few signs you can look for in the filesystem, but they may not be / are not foolproof

    • Heroku instances all have the path /app - the files and scripts that are running will be under this too, so you can check for the presence of the directory and/or that the scripts are being run from under it.

    • There is an empty directory /etc/heroku

    • /etc/hosts may have some heroku related domains added ~ $ cat /etc/hosts .dyno.rt.heroku.com

    Any of these can and may change at any moment.

    Your milage may vary

提交回复
热议问题