From 0debaadd9056558a9e1ac7e041fb3f0eb4b8f20f Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 5 Apr 2014 17:43:36 -0400 Subject: [PATCH] tweaks to how the app ring-handler is set up --- project.clj | 2 +- src/main.clj | 4 ++-- src/toascii/handler.clj | 25 +++++++++++++------------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/project.clj b/project.clj index 1e30052..aa6f609 100644 --- a/project.clj +++ b/project.clj @@ -19,7 +19,7 @@ :main main :plugins [[lein-ring "0.8.10"] [lein-environ "0.4.0"]] - :ring {:handler toascii.handler/app + :ring {:handler toascii.handler/handle-app :init toascii.handler/init :destroy toascii.handler/destroy} :profiles {:uberjar {:aot :all} diff --git a/src/main.clj b/src/main.clj index 1c7e335..663a7aa 100644 --- a/src/main.clj +++ b/src/main.clj @@ -2,13 +2,13 @@ (:require [ring.middleware.file :refer [wrap-file]] [ring.middleware.file-info :refer [wrap-file-info]] [ring.server.standalone :refer [serve]] - [toascii.handler :refer [app init destroy]]) + [toascii.handler :refer [handle-app init destroy]]) (:gen-class)) (defonce server (atom nil)) (defn get-handler [] - (-> #'app + (-> #'handle-app (wrap-file "resources") (wrap-file-info))) diff --git a/src/toascii/handler.clj b/src/toascii/handler.clj index d43f7fc..0f31785 100644 --- a/src/toascii/handler.clj +++ b/src/toascii/handler.clj @@ -15,20 +15,24 @@ (route/resources "/") (route/not-found "Not Found")) -(defonce routes (find-routes "toascii.routes." app-routes)) +(defonce ring-app (atom nil)) -(def app (app-handler - routes - :middleware [wrap-exceptions wrap-servlet-context-path] - :access-rules [] - :formats [:json-kw :edn])) +(defn handle-app [request] + (@ring-app request)) (defn init [] (set-config! [:shared-appender-config :spit-filename] "toascii.log") (set-config! [:appenders :spit :enabled?] true) (set-config! [:fmt-output-fn] log-formatter) - (log :info "toascii started successfully") + (log :info "Starting up ...") + + (reset! ring-app + (app-handler + (find-routes "toascii.routes." app-routes) + :middleware [wrap-exceptions wrap-servlet-context-path] + :access-rules [] + :formats [:json-kw :edn])) (when (env :dev) (log :info "Dev environment. Template caching disabled.") @@ -36,8 +40,5 @@ (flf/load-all!)) -(defn destroy - "destroy will be called when your application - shuts down, put any clean up code here" - [] - (log :info "toascii is shutting down...")) +(defn destroy [] + (log :info "Shutting down ..."))