Fork me on GitHub
#reitit
<
2022-10-20
>
mafcocinco14:10:47

I’m writing middleware for ring that needs access to path-params. I assume reitit has some default middleware that is used to attach this data the request object. In my server, the path-params are available to the handler function when the request object arrives. However, they are not present when I inspect the request object in my middleware function. Is there a best practice way to trigger reitit adding the path-params data before the request object arrives to my middleware function? Perhaps inserting the reitit default middleware explicitly before my middelware?

wevrem18:10:29

Yes, it sounds like a situation of changing the order of your middleware.

mafcocinco21:10:22

Great. Do you have any specific details of which middleware generates the path-params value? I was digging through the code but all I could find was in a wrapper around the handler which appears to get invoked right before the handler is called. Didn’t seem like that was configurable.

wevrem22:10:55

I think it is one of the middlewares that is supplied as part of ring/ring-defaults, but I don’t remember off the top of my head which one.

wevrem23:10:20

That may not be helpful to you if you are not using ring-defaults. But here is another idea, something I was just reading about the other day. Look under reitit’s documentation for middleware transformation. They provide a transform function that will show you incremental diff’s of the request as each middleware performs its changes. That will let you narrow down exactly where things are happening.

thumbsup_all 2