1. Krešimir Šojat
  2. neman

Commits

Kresimir Sojat  committed 39d8be4

Mapper now takes paths and rules as references and will attach watchers to them so mapper can be reconfigured while server is running.

  • Participants
  • Parent commits 8d38d48
  • Branches default

Comments (0)

Files changed (1)

File src/net/ksojat/neman/web.clj

View file
 
 (def redirect-to)
 
-
-
 (defn handle-url [url-path [[matcher path view] & rs]]
   (if-let [args (matcher url-path)]
     (binding [*current-path* path]
           (update-response *response* res))))
     (when (seq rs) (recur url-path rs))))
 
+(defn update-routes [_ paths rules]
+  (create-routes paths rules))
+
 (defn mapper [paths rules]
-  (let [routes (create-routes paths rules)]
+  (let [routes      (atom '())
+        swap-routes #(swap! routes update-routes @paths @rules)
+        update-on   #(add-watcher % :send (agent nil) (fn [& _] (swap-routes)))]
+    (swap-routes)
+    (update-on paths)
+    (update-on rules)
     (jetty/handler
       (fn [target request response dispatch]
-        (binding [*request* request, *response* response, *paths* paths, *rules* rules, *routes* routes]
-          (handle-url target routes))))))
+        (binding [*request*  request
+                  *response* response
+                  *paths*    @paths
+                  *rules*    @rules
+                  *routes*   @routes]
+          (handle-url target @routes))))))
 
-; TODO: Finish this code
-(defn ref-mapper [paths rules]
-  (let [paths (fn [] @paths)
-        rules (fn [] @rules)]))