Fork me on GitHub
#reitit
<
2022-02-24
>
wombawomba16:02:40

I'm running into a situation where Retit doesn't inject :form-params, :params, and :query into a request before it passes it off to the middleware stack for routes with {:middleware []} — any idea what could be causing this or how I can debug it? It's causing reitit.ring.coercion/coerce-request-middleware to throw an exception.

ikitommi16:02:02

you need to have the parameter-middleware (from ring or reitit, doing the same) for that.

ikitommi16:02:33

there is a request-debugging tool that shows the request & response before and after each middleware step, which is useful in debugging.

ikitommi16:02:07

there should be “api-middleware” with all the releavant mw in it (and in right order)

wombawomba16:02:14

I am using ring.middleware.params/wrap-params at the start of my middleware stack

ikitommi16:02:55

that should do it.

wombawomba16:02:07

and I did try using if that's what you mean

ikitommi16:02:16

didn’t help?

wombawomba16:02:25

nope — well, the first 'frame' it prints (`--- :request ---`) is missing those keys for the routes with :middleware []

wombawomba16:02:19

perhaps it's just skipping over wrap-params when printing, and that middleware doesn't get run for these routes?

wombawomba16:02:30

I just tried writing a middleware transformer that just prints out which middleware is applied to each route, and curiously enough, it seems like the middleware stack is reversed for the routes with {:middleware []}

wombawomba16:02:49

so that's probably the problem — the question then would be, what could be causing it?

wombawomba16:02:32

(...actually, I realized it's not that "skips" wrap-params — it just doesn't print the name of that particular middleware. The problem is indeed that it get applied first instead of last for routes with {:middleware []})

wombawomba16:02:20

@U055NJ5CC I think I figured it out, and it seems to be a bug in Reitit

wombawomba16:02:35

specifically, this behavior only occurs when the list of middleware passed to reitit.ring/router is a non-vector sequence

wombawomba16:02:39

if I change my router call to (reitit.ring/router router (update-in config [:data :middleware] vec)), the problem goes away

wombawomba16:02:52

my guess would be that you're using something like reduce with conj when joining together middleware vectors