blob: 46353173e310b977c9028a1850777fc0dc09f2c9 (
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
59
60
61
62
63
|
(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)))
|