(ns dionysus.web.admin (:require [reitit.ring :as rring] [org.httpkit.server :as http-server] [ring.middleware.oauth2 :as rmoauth2] [dotenv :as env] [ring.middleware.params :as rmparams] [ring.middleware.session :as rmsessions] [dionysus.utils :as dutils] [dionysus.web.admin.home :as dwahome] [dionysus.web.admin.home.blacklist :as dwahblacklist] [dionysus.web.admin.home.server-settings :as dwahserver-settings])) (def ^:private routes [["/" {:get {:handler dwahome/handle}}] ["/blacklist" ["/" {:get {:handler dwahblacklist/handle}}] ["/add" {:post {:handler dwahblacklist/handle-add}}] ["/change/:index" {:post {:handler dwahblacklist/handle-change}}] ["/delete/:index" {:delete {:handler dwahblacklist/handle-delete}}]] ["/server-settings" {:post {:handler dwahserver-settings/handle}}] ["/assets/*" (rring/create-resource-handler)]]) (def ^:private handler (-> routes rring/router (rring/ring-handler (rring/redirect-trailing-slash-handler)) (rmoauth2/wrap-oauth2 {:spotify {:authorize-uri "https://accounts.spotify.com/authorize" :access-token-uri "https://accounts.spotify.com/api/token" :client-id (env/env "SPOTIFY_CLIENT_ID") :client-secret (env/env "SPOTIFY_CLIENT_SECRET") :scopes ["user-read-private" "user-modify-playback-state" "user-read-currently-playing"] :launch-uri "/auth" :redirect-uri "/callback" :landing-uri "/"}}) rmsessions/wrap-session rmparams/wrap-params delay)) (def ^:private stop-fn (atom nil)) (defn start-server! [] (when (fn? @stop-fn) (@stop-fn)) (reset! stop-fn (http-server/run-server @handler {:port (-> (env/env "ADMIN_PORT") (dutils/try-parse-int 8081))}))) #_(start-server!)