summaryrefslogtreecommitdiff
path: root/src/clj/nicktodo/handler.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clj/nicktodo/handler.clj')
-rw-r--r--src/clj/nicktodo/handler.clj35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/clj/nicktodo/handler.clj b/src/clj/nicktodo/handler.clj
new file mode 100644
index 0000000..e0c9a4c
--- /dev/null
+++ b/src/clj/nicktodo/handler.clj
@@ -0,0 +1,35 @@
+(ns nicktodo.handler
+ (:require
+ [nicktodo.middleware :as middleware]
+ [nicktodo.layout :refer [error-page]]
+ [nicktodo.routes.home :refer [home-routes]]
+ [reitit.ring :as ring]
+ [ring.middleware.content-type :refer [wrap-content-type]]
+ [ring.middleware.webjars :refer [wrap-webjars]]
+ [nicktodo.env :refer [defaults]]
+ [mount.core :as mount]))
+
+(mount/defstate init-app
+ :start ((or (:init defaults) (fn [])))
+ :stop ((or (:stop defaults) (fn []))))
+
+(mount/defstate app-routes
+ :start
+ (ring/ring-handler
+ (ring/router
+ [(home-routes)])
+ (ring/routes
+ (ring/create-resource-handler
+ {:path "/"})
+ (wrap-content-type
+ (wrap-webjars (constantly nil)))
+ (ring/create-default-handler
+ {:not-found
+ (constantly (error-page {:status 404, :title "404 - Page not found"}))
+ :method-not-allowed
+ (constantly (error-page {:status 405, :title "405 - Not allowed"}))
+ :not-acceptable
+ (constantly (error-page {:status 406, :title "406 - Not acceptable"}))}))))
+
+(defn app []
+ (middleware/wrap-base #'app-routes))