You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wanijo/src/wanijo/handler.clj

65 lines
2.0 KiB

(ns wanijo.handler
(:require [compojure.core
:refer [defroutes routes]]
[compojure.route :as route]
[ring.middleware.defaults
:refer [wrap-defaults site-defaults]]
[ring.util.response :as rur]
[ring.middleware.session.cookie :as session-cookie]
[ring.middleware.json :as ring-json]
[clojure.spec.alpha :as spec]
[wanijo.home.routes :as home-routes]
[wanijo.schema
[routes :as schema-routes]
[middleware :as schema-middleware]]
[wanijo.user.routes :as user-routes]
[wanijo.attribute.routes :as attr-routes]
[wanijo.instance.routes :as instance-routes]
[wanijo.visualisation.routes :as vis-routes]
[wanijo.tag.routes :as tag-routes]
[wanijo.framework
[auth :as auth]
[devmode :as devmode]
[routing :refer [path]]]))
(defn- wrap-login-redirect [handler]
(fn [req]
(if (get-in req [:session :ident])
(handler req)
(rur/redirect (path :auth-login)))))
(defroutes app-routes
(routes auth/routes)
(wrap-login-redirect
(routes home-routes/routes
schema-routes/routes
user-routes/routes
attr-routes/routes
instance-routes/routes
vis-routes/routes
tag-routes/routes))
(route/not-found "Not Found"))
(def standalone-app
(-> app-routes
devmode/wrap-devmode
schema-middleware/wrap-user-schemas
(wrap-defaults site-defaults)))
(defn wrap-spec-asserts [handler]
(fn [req]
(spec/check-asserts true)
(handler req)))
(def app
(-> app-routes
wrap-spec-asserts
devmode/wrap-devmode
schema-middleware/wrap-user-schemas
ring-json/wrap-json-response
(wrap-defaults
(assoc-in site-defaults
[:session :store]
(session-cookie/cookie-store
{:key "1234567890123456"})))))