Clojure Ring:如何确定开发服务器是否为 运行?

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

我有一个包含 Clojure 和 ClojureScript 代码的项目。当我通过 lein ring server 运行 我的服务器时,我想包含未优化的 ClojureScript,否则我会优化 ClojureScript。执行此操作的惯用方法是什么?

我正在使用:

[[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"]]

我的处理程序很简单:

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

这是我的服务器指令:

:ring {:handler webapp.core/app}

在我看来,我正在寻找能够做到这一点的方法:

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

执行此操作的惯用方法是使用 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

如果你想能够识别开发服务器运行,你可以使用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作为灵感。