diff --git a/src/reitit/ring.cljc b/src/reitit/ring.cljc index 9fe6aec6..f866b705 100644 --- a/src/reitit/ring.cljc +++ b/src/reitit/ring.cljc @@ -6,7 +6,6 @@ (def http-methods #{:get :head :patch :delete :options :post :put}) (defrecord Methods [get head post put delete trace options connect patch any]) -(defrecord Endpoint [meta handler]) (defn- group-keys [meta] (reduce-kv @@ -56,30 +55,22 @@ (update acc method expand opts) acc)) meta http-methods)]) -(defn compile-handler [[path meta] opts] +(defn compile-result [[path meta] opts] (let [[top childs] (group-keys meta)] (if-not (seq childs) - (map->Methods - {:any (map->Endpoint - {:handler (middleware/compile-handler [path top] opts) - :meta top})}) - (let [any-handler (if (:handler top) (middleware/compile-handler [path meta] opts))] + (let [middleware (middleware/compile-result [path top] opts)] + (map->Methods {:any (middleware/compile-result [path top] opts)})) + (let [any-handler (if (:handler top) (middleware/compile-result [path meta] opts))] (reduce-kv (fn [acc method meta] - (let [meta (meta-merge top meta) - handler (middleware/compile-handler [path meta] opts method)] - (assoc acc method (map->Endpoint - {:handler handler - :meta meta})))) - (map->Methods - {:any (map->Endpoint - {:handler (if (:handler top) (middleware/compile-handler [path meta] opts)) - :meta top})}) + (let [meta (meta-merge top meta)] + (assoc acc method (middleware/compile-result [path meta] opts method)))) + (map->Methods {:any any-handler}) childs))))) (defn router ([data] (router data nil)) ([data opts] - (let [opts (meta-merge {:coerce coerce-handler, :compile compile-handler} opts)] + (let [opts (meta-merge {:coerce coerce-handler, :compile compile-result} opts)] (reitit/router data opts))))