This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-13
Channels
- # babashka (10)
- # beginners (27)
- # calva (91)
- # cestmeetup (3)
- # cider (27)
- # clj-kondo (12)
- # cljs-dev (4)
- # clojars (13)
- # clojure (35)
- # clojure-europe (30)
- # clojure-france (3)
- # clojure-houston (1)
- # clojure-nl (11)
- # clojure-norway (29)
- # clojure-spec (23)
- # clojure-sweden (5)
- # clojure-uk (128)
- # clojurescript (69)
- # conjure (44)
- # core-async (27)
- # cursive (13)
- # emacs (9)
- # events (3)
- # fulcro (52)
- # graphql (4)
- # jobs (2)
- # jobs-discuss (46)
- # kaocha (4)
- # luminus (12)
- # nrepl (10)
- # off-topic (29)
- # re-frame (17)
- # reitit (20)
- # remote-jobs (4)
- # rewrite-clj (1)
- # ring (4)
- # rum (13)
- # shadow-cljs (40)
- # sql (1)
- # xtdb (1)
I'm trying to figure out how to troubleshoot failing coercions, I can't seem to get a handle on the actual error.. attached here is my ring handler and retitit route. I'd like to apply expound to the spec error (https://cljdoc.org/d/metosin/reitit/0.5.5/doc/ring/pluggable-coercion#pretty-printing-spec-errors), but I can't even get a handle on the spec error heh. Anyone have tips?
@ramblurr the coercion with ring is done using middleware, not using a :compile
hook.
you could check some of the examples, like: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj
thanks @ikitommi that really helped. :reitit.middleware/transform dev/print-request-diffs
is amazing!
and now adding the custom exception middleware to use expound as described in the docs, works 😁
My reitit ring handler is wrapped in the https://github.com/ring-clojure/ring-defaults middleware (wrap-defaults (reitit.ring/ring-handler (reitit.ring/router ....)))
I'd like to invert it so that the defaults middlewares are all inside, defined in the :middleware
key of the reitit handler definiton.
you can look at the source code of the wrap-defaults
and put the relevant mw into router :data
:middleware
vector, e.g.
(ring/router
{:data {:middleware [[wrap-anti-forgery (get-in config [:security :anti-forgery] false)]
[wrap-flash (get-in config [:session :flash] false)]]}})
from: https://github.com/ring-clojure/ring-defaults/blob/master/src/ring/middleware/defaults.clj#L99-L100
The naming confuses me. Is it convention that a function prefixed with wrap-
is the higher order function that accepts the handler and returns a function (fn [request])
(the actual middleware?)
When one talks of middleware are they referring to this handler wrapping function or the inner function?
the vector syntax is meant for the wrap-
style middleware. the handler is injected as first argument, e.g. [wrap-something {:option "kikka"}]
is turned into (wrap-something handler {:options "kikka"})
at router creation time.
I think that the “thread-first optimized” convention is really bad in Ring as it couples middleware creation and configuration. All reitit middleware are named -middleware
, of type options -> handler -> handler
["/something" {:get api/something-handler}
`["/:id" {:get api/something-id-handler}`
["/subthing" {:get api/subthing-handler}]]]
/something
matches, /something/asdfasdfasdf/subthing
matches, but /something/asdfasdfasdf
["/something" {:get api/something-handler}
["/:id"
["" {:get api/something-id-handler}]
["/subthing" {:get api/subthing-handler}]]]
should workI can't seem to find the docs regarding routing syntax when it comes to nested routes.
What is the difference between ["" ["/" {:name :root}] ["/sub1" {:name :sub1 }]]
and [["/" :foo] ["/sub1"]]
When to use ""
and when not? And how do you properly add another level deeper (so /sub1/sub2
) when you want each level to have its own view?