(ns chef.routes (:require [reitit.ring :as rring] [ring.middleware.oauth2 :as rmoauth2] [ring.middleware.params :as rmparams] [ring.middleware.session :as rmsession] [dotenv :as env] [clojure.string :as cstr] [chef.pages.home :as cphome] [chef.pages.admin :as cpadmin] [chef.pages.recipe :as cprecipe] [chef.components.search :as ccsearch] [chef.pages.admin.api :as cpaapi] [chef.pages.admin.recipe-editor :as cparecipe-editor])) (def router [["/" {:get {:handler cphome/handler}}] ["/recipes/:id" {:get cprecipe/handler}] ["/static/*" (rring/create-resource-handler)] ["/admin" ["/" {:get {:handler cpadmin/handler}}] ["/recipe-editor/:id" {:get {:handler cparecipe-editor/handler}}]] ["/components" ["/search" {:get {:handler ccsearch/handler}}]] ["/api" ["/admin" ["/create-category" {:post {:handler cpaapi/create-category}}] ["/delete-category/:id" {:delete {:handler cpaapi/delete-category}}] ["/edit-category/:id" {:post {:handler cpaapi/edit-category}}] ["/create-recipe" {:post {:handler cpaapi/create-recipe}}] ["/delete-recipe/:id" {:delete {:handler cpaapi/delete-recipe}}] ["/edit-recipe/:id" {:post {:handler cpaapi/edit-recipe}}]]]]) (def ring-handler (delay (-> router rring/router (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 rmsession/wrap-session)))