mirror of
https://gitlab.com/wheres-the-tp/server.git
synced 2026-01-25 04:24:56 -06:00
45 lines
1.9 KiB
Clojure
45 lines
1.9 KiB
Clojure
(ns aretherecookies.app
|
|
(:gen-class)
|
|
(:require [aretherecookies.handler :refer [quantity-add-handler
|
|
quantity-get-handler
|
|
faves-get-handler
|
|
faves-put-handler
|
|
faves-delete-handler
|
|
product-search-handler]]
|
|
[aretherecookies.auth :refer [auth0-auth-backend]]
|
|
[aretherecookies.search.search :refer init-search]
|
|
[environ.core :refer [env]]
|
|
[compojure.handler :refer [api]]
|
|
[compojure.core :refer [defroutes GET POST PUT DELETE]]
|
|
[ring.adapter.jetty :as jetty]
|
|
[ring.middleware.anti-forgery :refer :all]
|
|
[ring.middleware.json :refer [wrap-json-body]]
|
|
[ring.middleware.multipart-params :refer [wrap-multipart-params]]
|
|
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]
|
|
[buddy.auth.middleware :refer [wrap-authentication wrap-authorization]]))
|
|
|
|
(defroutes app-routes
|
|
(GET "/" [] (str {:csrf-token *anti-forgery-token*}))
|
|
(POST "/test" [] "ok")
|
|
(POST "/quantity" [] quantity-add-handler)
|
|
(GET "/quantity" [] quantity-get-handler)
|
|
(POST "/faves" [] faves-get-handler)
|
|
(PUT "/fave" [] faves-put-handler)
|
|
(DELETE "/fave" [] faves-delete-handler)
|
|
(GET "/products/:search" [] product-search-handler))
|
|
|
|
(def app-config (assoc-in api-defaults [:security :anti-forgery] false))
|
|
|
|
(def app (wrap-defaults app-routes app-config))
|
|
|
|
(defn -main
|
|
[& [port]]
|
|
(let [port (Integer. (or port (env :port) 3000))]
|
|
(init-search)
|
|
(->
|
|
(api #'app)
|
|
(wrap-authentication auth0-auth-backend)
|
|
(wrap-authorization auth0-auth-backend)
|
|
wrap-multipart-params
|
|
(wrap-json-body {:keywords? true})
|
|
(jetty/run-jetty {:port port :join? false}))))
|