Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current hostname in Heroku

I'm playing around with deploying Clojure/Noir apps on Heroku and I've got my app mostly working. However, one final piece I need is to figure out the hostname of my app when deployed on Heroku. Ideally, I want to do this dynamically instead of hard-coding it.

So, if for example, my app's URL is 'http://freez-windy-1800.herokuapp.com', I want to be able to dynamically get this within my clojure code.

I know that I can look at the incoming request to figure this out, but ideally, I'd like to have some sort of 'setting' where I evaluate an expression once and save the value in a variable that I can then use (coming from the Python/Django world, I'm thinking of the settings.py equivalent in Clojure).

For reference, the code I'm deploying is available at https://github.com/rmanocha/cl-short.

like image 236
Rishabh Manocha Avatar asked May 21 '12 13:05

Rishabh Manocha


People also ask

Can I add a custom domain name to my Heroku app?

For security purposes, you must verify your Heroku account to add domains to apps. Heroku does not provide a domain registration service (for registering a custom domain name) or a DNS provider service (for hosting the DNS servers that point your custom domain name to your app).

What is the default Heroku app name?

By default, a Heroku app is available at its Heroku domain, which has the form [name of app].herokuapp.com. For example, an app named serene-example-4269 is hosted at serene-example-4269.herokuapp.com. Heroku DNS uses DNSSEC to authenticate requests to all herokuapp.com and herokudns.com domains.

How do I point my DNS provider to Heroku?

After you add a domain with the heroku domains:add command, you need to point your DNS provider at the DNS target provided by Heroku. You can view this DNS target with the heroku domains command (see View existing domains for details). You usually configure a new CNAME record with your DNS provider to point it at Heroku.

How to list webhook deliveries on an app in Heroku?

list webhook deliveries on an app USAGE $ heroku webhooks:deliveries OPTIONS -a, --app=app app to run command against -r, --remote=remote git remote of app to use -s, --status=status filter deliveries by status EXAMPLE $ heroku webhooks:deliveries info for a webhook event on an app


1 Answers

You could set an environment variable in Heroku by

heroku config:add BASE_IRI=http://freez-windy-1800.herokuapp.com

and read it back in Clojure

(defn- base-iri []
  (or (System/getenv "BASE_IRI") "http://localhost/"))

Heroku already sets the PORT you can use

(defn -main []
  (let [port (Integer. (or (System/getenv "PORT") 8080))]
    (run-jetty #'app {:port port})))

Works for me in different environments.

like image 94
Jochen Rau Avatar answered Sep 25 '22 21:09

Jochen Rau