summaryrefslogtreecommitdiff
path: root/src/chef/routes.clj
blob: d21cb0d332de5ca60d799ae734ef587b7cc18f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(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]
            [ring.middleware.reload :as rmreload]
            [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}]
              ["/thumbnail" {:get cprecipe/thumbnail-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}}]

               ["/delete-thumbnail/:id" {:delete {:handler cpaapi/delete-thumbnail}}]]]])

(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
                             rmmultiparams/wrap-multipart-params
                             rmsession/wrap-session)))