Browse Source

improved handler loading/structure; added two (empty) handlers

Brandon Wong 2 years ago
parent
commit
d1ae5dd1be

+ 25 - 2
src/attendant/handler.clj

@@ -1,12 +1,35 @@
 (ns attendant.handler
   (:require
-   [compojure.core :refer [ANY defroutes OPTIONS]]
+   [attendant.handlers.playlist :refer [playlist]]
+   [attendant.handlers.witwibw :refer [witwibw]]
+   [clojure.string :as string]
+   [compojure.core :refer [ANY context defroutes OPTIONS routes]]
    [compojure.route :refer [not-found]]
-   [ring.util.response :refer [header]]))
+   [ring.util.response :refer [header response]]))
+
+(def simple-functions
+  [["/witwibw" witwibw]])
+
+(def complex-functions
+  [["/playlist" playlist]])
 
 (defroutes app
   (OPTIONS "*" [] "")
   (ANY "/" [] "attendant server")
+
+  (->> simple-functions
+       (map #(ANY (first %) [] (second %)))
+       (apply routes))
+
+  (->> complex-functions
+       (map #(context (first %) [] ((second %))))
+       (apply routes))
+
+  (ANY "/directory" [] (->> (concat simple-functions complex-functions)
+                            (map first)
+                            (string/join "\n")
+                            response))
+
   (not-found "nothing here (yet)"))
 
 (defn make-handler []

+ 12 - 0
src/attendant/handlers/playlist.clj

@@ -0,0 +1,12 @@
+(ns attendant.handlers.playlist
+  (:require
+   [clojure.java.io :as io]
+   [compojure.core :refer [ANY routes]]
+   [ring.util.response :refer [response]]))
+
+(defn playlist []
+  (io/make-parents "playlist/activity.log")
+  (routes
+   (ANY "/" [] "playlist root!")
+   (ANY "/test" [] (response (slurp "blah")))
+   (ANY "/sub" [] "playlist sub!")))

+ 9 - 0
src/attendant/handlers/witwibw.clj

@@ -0,0 +1,9 @@
+(ns attendant.handlers.witwibw
+  (:require
+   [ring.util.response :refer [response]]))
+
+(defn witwibw [req]
+  (println "\n\n")
+  (println req)
+  ;(ANY "/witwibw" [] (response (slurp "/var/www/intranet/stellar.log")))
+  (response "witwibw!?"))