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

68 lines
2.1 KiB

(ns wanijo.handler
(:require [clojure.string :refer [starts-with?]]
[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.infra
[auth :as auth]
[routing :refer [path]]
[gzip :as gzip]
[neo4j :as neo4j]]))
(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
schema-middleware/wrap-user-schemas!
ring-json/wrap-json-response
(wrap-defaults site-defaults)
gzip/wrap-gzip))
(defn wrap-spec-asserts [handler]
(fn [req]
(spec/check-asserts true)
(handler req)))
(def dev-app
(-> app-routes
wrap-spec-asserts
schema-middleware/wrap-user-schemas!
ring-json/wrap-json-response
(wrap-defaults
(assoc-in site-defaults
[:session :store]
(session-cookie/cookie-store
{:key (subs (neo4j/uuid) 0 16)})))
gzip/wrap-gzip))