Skip to content

Commit

Permalink
Implement reitit reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
markokocic committed Feb 13, 2024
1 parent a0b246a commit 4496338
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
:handler #ig/ref :handler/ring}

:handler/ring
{:router #ig/ref :router/core <% if metrics? %>
{:router #ig/ref :router/core
:env #ig/ref :system/env <% if metrics? %>
:metrics #ig/ref :metrics/prometheus <% endif %>
:api-path "/api"
:cookie-secret #or [#env COOKIE_SECRET "<<default-cookie-secret>>"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
[reitit.swagger-ui :as swagger-ui]))

(defmethod ig/init-key :handler/ring
[_ {:keys [router api-path] :as opts}]
[_ {:keys [router api-path env] :as opts}]
(ring/ring-handler
router
(if (= env :dev)
(router)
(constantly router))
(ring/routes
;; Handle trailing slash in routes - add it + redirect to it
;; https://github.com/metosin/reitit/blob/master/doc/ring/slash_handler.md
Expand All @@ -32,8 +34,13 @@

(defmethod ig/init-key :router/routes
[_ {:keys [routes]}]
(apply conj [] routes))
(vec (map
(fn [route]
(if (fn? route)
(route)
route))
routes)))

(defmethod ig/init-key :router/core
[_ {:keys [routes] :as opts}]
(ring/router ["" opts routes]))
#(ring/router ["" opts routes]))
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
[_ {:keys [base-path]
:or {base-path ""}
:as opts}]
[base-path route-data (api-routes opts)])
(fn [] [base-path route-data (api-routes opts)]))

0 comments on commit 4496338

Please sign in to comment.