(ns chef.routes (:require [reitit.ring :as rring] [ring.middleware.oauth2 :as rmoauth2] [ring.middleware.params :as rmparams] [ring.middleware.multipart-params :as rmmultiparams] [ring.middleware.session :as rmsession] [dotenv :as env] [clojure.string :as cstr] [chef.frontend.admin.recipe-editor :as cfarecipe-editor] [chef.frontend.admin :as cfadmin] [chef.frontend.visitor.recipe :as cfvrecipe] [chef.frontend.visitor.recipe.thumbnail :as cfvrthumbnail] [chef.frontend.visitor.search :as cfvsearch] [chef.frontend.visitor.home :as cfvhome] [chef.api.admin.category :as caacategory] [chef.api.admin.recipe :as caarecipe])) (def router [["/static/*" (rring/create-resource-handler)] ;;; Visitor routes ["/" {:get {:handler cfvhome/handler}}] ["/recipes/:id" ["/" {:get {:handler cfvrecipe/handler}}] ["/thumbnail" {:get {:handler cfvrthumbnail/handler}}]] ["/components" ["/search" {:get {:handler cfvsearch/handler}}]] ;;; Admin routes ["/admin" ["/" {:get {:handler cfadmin/handler}}] ["/recipe-editor/:id" {:get {:handler cfarecipe-editor/handler}}]] ;;; API routes ["/api" ["/admin" ["/category" ["/create" {:post {:handler caacategory/handle-create}}] ["/:id" {:post {:handler caacategory/handle-edit} :delete {:handler caacategory/handle-delete}}]] ["/recipe" ["/create" {:post {:handler caarecipe/handle-create}}] ["/:id" ["/" {:post {:handler caarecipe/handle-edit} :delete {:handler caarecipe/handle-delete}}] ["/thumbnail" {:delete {:handler caarecipe/handle-delete-thumbnail}}]]]]]]) (def ring-handler (delay (-> router (rring/router {:conflicts nil}) (rring/ring-handler (rring/redirect-trailing-slash-handler)) (rmoauth2/wrap-oauth2 {:auth {:authorize-uri (env/env "OAUTH_AUTH_URI") :access-token-uri (env/env "OAUTH_ACCESS_TOKEN_URI") :client-id (env/env "OAUTH_CLIENT_ID") :client-secret (env/env "OAUTH_CLIENT_SECRET") :scopes (cstr/split (env/env "OAUTH_SCOPES") #",") :launch-uri "/auth" :redirect-uri "/auth/callback" :landing-uri "/admin" :pkce? true}}) rmparams/wrap-params rmmultiparams/wrap-multipart-params rmsession/wrap-session)))