This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-24
Channels
- # aleph (3)
- # beginners (17)
- # boot (8)
- # cider (61)
- # cljdoc (13)
- # cljs-dev (2)
- # clojure (66)
- # clojure-boston (1)
- # clojure-italy (4)
- # clojure-nl (7)
- # clojure-russia (7)
- # clojure-spec (19)
- # clojure-uk (80)
- # clojurescript (73)
- # core-async (4)
- # cursive (6)
- # data-science (1)
- # datomic (33)
- # docs (13)
- # emacs (17)
- # figwheel-main (28)
- # fulcro (12)
- # graphql (1)
- # jobs (3)
- # leiningen (4)
- # luminus (1)
- # off-topic (1)
- # parinfer (1)
- # pedestal (46)
- # protorepl (3)
- # re-frame (30)
- # reagent (47)
- # reitit (10)
- # ring (1)
- # shadow-cljs (94)
- # spacemacs (12)
- # specter (16)
- # tools-deps (6)
- # uncomplicate (1)
- # vim (9)
@ikitommi hi! tried to follow this guide: https://metosin.github.io/reitit/advanced/composing_routers.html, however, can't get how to build handler with such dynamic routing:
["/*" {:handler (fn [request]
;; (def tmp-request request)
(let [handler (-> @external-router
(r/match-by-path (:uri request))
:result
)]
(handler request)))
:swagger {:id ::external-api
:tags ["Available endpoints"]}
:name ::endpoints}
]
this kind of worked, but it seems like middleware was not applied...@zarkone using reitit-ring? With it, the middleware is applied by the ring-handler
function. So, you should re-create such in the endpoint and pass is the request.
thanks, just got to ring-handler
point also: external-router
is reitit-router, not ring: (reset! external-router (reitit.core/router (generate-external-router)))
so, we've got it to work, thanks 🙂 however, we've found that for nested routes you have to add coersions explicitly:
(defstate routes
:start (fn []
(reset! external-router (ring/router (generate-external-router) {:data {:middleware [ring.coercion/coerce-exceptions-middleware
ring.coercion/coerce-request-middleware
ring.coercion/coerce-response-middleware]
}}))
["/*" {:handler (fn [request]
(def tmp-request request)
(let [request tmp-request ;;for debug here
handler (-> @external-router
(ring/ring-handler)
)]
handler
(handler request)
)
)
:swagger {:id ::external-api
:tags ["Available endpoints"]}
:name ::endpoints}
]
)
:stop nil)
hope this makes sense!