muhuk
muhuk

Reputation: 16085

Clojure Ring: How to determine if development server is running?

I have a project containing both Clojure & ClojureScript code. I would like to include unoptimized ClojureScript when I run my server via lein ring server and optimized ClojureScript otherwise. What is the idiomatic way to do this?

I am using:

[[bidi "1.19.0"]
 [hiccup "1.0.5"]
 [org.clojure/clojure "1.7.0-beta3"]
 [org.clojure/clojurescript "0.0-3269"]]

[[lein-cljsbuild "1.0.4"]
 [lein-ring "0.9.4"]]

My handler is just a simple one:

(def app (-> ["/" {:get {"" index-view}}]
             (compile-route)
             (make-handler)))

and this is my server directive:

:ring {:handler webapp.core/app}

I am looking for a way to be able to do this in my views:

(dev-server? request) ;; => true if it's a development server, otherwise false.

Upvotes: 1

Views: 429

Answers (1)

schaueho
schaueho

Reputation: 3504

The idiomatic way to do this is to use leiningen profiles, using the :dev profile. You can then ensure inside the dev profile that your ClojureScript build is happening without optimization, cf. the leiningen cljsbuild compilation profiles.

If you want to be able to identify the devserver running, you can use environ -- include :env {:dev true} in your :dev profile and then in your code you can just call (env :dev). You might want to take a look at the reagent-template for inspiration.

Upvotes: 1

Related Questions