This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-06
Channels
- # beginners (95)
- # boot (3)
- # cider (13)
- # cljs-dev (9)
- # cljsjs (1)
- # cljsrn (35)
- # clojure (78)
- # clojure-dev (5)
- # clojure-italy (6)
- # clojure-nl (9)
- # clojure-russia (13)
- # clojure-spec (1)
- # clojure-uk (74)
- # clojurescript (59)
- # community-development (6)
- # core-async (41)
- # css (110)
- # data-science (2)
- # datomic (22)
- # defnpodcast (1)
- # devcards (1)
- # docs (1)
- # editors (6)
- # emacs (51)
- # figwheel (1)
- # fulcro (66)
- # jobs (1)
- # jobs-discuss (75)
- # lumo (51)
- # mount (2)
- # off-topic (33)
- # pedestal (24)
- # proton (3)
- # re-frame (29)
- # reagent (92)
- # reitit (16)
- # shadow-cljs (16)
- # spacemacs (4)
- # specter (6)
- # vim (6)
- # yada (7)
Me again. I've made lots of progress and moved all my routes over to reitit, which was really straightforward! I can't get wrap-resource
middleware working though, static things will only be served when I wrap the handler provided by rr/ring-handler
. So this works:
(wrap-resource
(rr/ring-handler
(rr/router [""
["/" {:handler index-page}]
["/banana" {:handler peel}]]))
"public")
But this does not:
(rr/ring-handler
(rr/router ["" {:middleware [[wrap-resource "public"]]}
["/" {:handler index-page}]
["/banana" {:handler peel}]]))
What am I misunderstanding?@conan wrap-resource is special middleware that serves routes behind the scens. Reitit is a route-first architecture: match first, then apply all the middleware for the matched route. Your second example doesn’t work because the route tree handles only exact matches “/” and “/banana” and thus, doesn’t match.
1) wrap the wrap-resouces
over the router (your first example) => this is not good as for all routes, the mw check if there is a static file present. This is extra IO and slows the app down.
2) add a wildcard route and serve static resources from there: ["/*" {:middleware [[wrap-resource "public"]]}]
+ disable the route conflict resolution (with :conflicts
router option)
3) wrap the default handler with the ring default handler
thanks. ok yes i see that i don't want to wrap everything in the static check. i'll look into the conflict resolution. i don't quite understand what you mean by 3)?
(ring/ring-handler
(ring/router
[["/" {:handler index-page}]
["/banana" {:handler peel}]])
(wrap-resource
(ring/create-default-handler)
"public"))
the ring-handler
takes optional second parameter which is the default-handler, it’s just a ring-handler
in 3, it first checks the resource, then serves the 404-406 based on the request, see https://metosin.github.io/reitit/ring/ring.html#default-handler