Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
- new-api-handler
  • Loading branch information
danielsz committed Jun 19, 2024
1 parent 254a921 commit 6f38b16
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/system/components/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(filter (comp :routes val) component))

(defn api-endpoints? [component]
(some #(contains? component %) [:api-handlers :api-handler]))
(contains? component :api-handler))

(defrecord Handler [default-handler options]
component/Lifecycle
Expand All @@ -28,7 +28,7 @@
routers (apply merge-routers routes)
handler (if (api-endpoints? component)
(let [site-router (ring/router (r/routes routers) {:data options})
api-router (for [api-handler (some #(get component %) [:api-handler :api-handlers])
api-router (for [api-handler (:api-handler component)
:let [api-routes ((:api-route api-handler) component)
api-middleware (:api-middleware api-handler)
api-prefix (get api-handler :api-prefix "/api")
Expand All @@ -47,13 +47,13 @@
[& {:keys [default-handler options]}]
(map->Handler {:default-handler default-handler :options options}))

(defn new-api-handlers
[xs]
(into [] (for [{:keys [api-route api-prefix api-middleware]} xs]
{:api-route api-route :api-prefix api-prefix :api-middleware api-middleware})))

(defn new-api-handler
[& {:as m}]
(new-api-handlers [m]))
(cond
(map? m) [m]
(vector? m) (into [] (for [{:keys [api-route api-prefix api-middleware]} m]
{:api-route api-route :api-prefix api-prefix :api-middleware api-middleware}))))




0 comments on commit 6f38b16

Please sign in to comment.