I created a compojure app using lein new compojure mongotest with lein 2.0, and a Procfile web: lein ring server-headless $PORT. This worked fine, but now when I add
(def mongolab-url (System/getenv "MONGOLAB_URI"))
(println "mongolab-url")
(println mongolab-url)
(mg/connect-via-uri! mongolab-url)
when I try git push heroku master Heroku eventually gives me
Compiling mongotest.handler
mongolab-url
nil
Exception in thread "main" java.lang.NullPointerException, compiling:(handler.clj:13:1)
... 25 more
Compilation failed: Subprocess failed
Error encountered performing task 'compile' with profile(s): 'production'
Suppressed exit
! Failed to build.
! Push rejected, failed to compile Clojure (Leiningen 2) app
I added these lines at the top level of handler.clj. Some of the older documentation I see the connection is created in main, but that must have been for older versions of compojure, as there's no main anymore (that I've found) in the generated app. Where should the connection get established in the current version? (Or is my Procfile not right?)
(Yes, MONGOLAB_URI is defined in heroku config)
The answer that worked for me and seems most idiomatic is to put the above connection into a function
initin that same file (myproject/handler.clj)and update the
project.cljfile ring descriptor line fromto