This is likely just a failure on my part to understand how wrap-routes is supposed to work, but I was hoping you could clarify. Usually I define my routes using a thread macro and then applying a series of middleware with the understanding that later middleware receive the request earlier. Now, sometimes I want these middleware to only run if it matches a known route so I use wrap-routes. Once I introduce wrap-routes into the equation, the ordering of my middleware gets rather messed up in a way I wouldn't expect!
Version: 1.5.1
I would expect:
All my non wrap-routes middleware to execute first and then if the route matches, my wrap-routes middleware to execute in the same order as they were defined. However, instead the wrap-routes middleware actually execute in the opposite order compared to the order my other middleware execute in.
Before request: 5
Before request: 2
Before request: 1
Before request: 3
Before request: 4
Before response: 4
Before response: 3
Before response: 1
Before response: 2
Before response: 5
I would expect:
Before request: 5
Before request: 2
Before request: 1
Before request: 4
Before request: 3
Before response: 3
Before response: 4
Before response: 1
Before response: 2
Before response: 5
Is this intentional behavior? Would you consider changing this? (I realize that changing ordering of execution of middleware may have subtle downstream impacts).
Hi James,
This is likely just a failure on my part to understand how wrap-routes is supposed to work, but I was hoping you could clarify. Usually I define my routes using a thread macro and then applying a series of middleware with the understanding that later middleware receive the request earlier. Now, sometimes I want these middleware to only run if it matches a known route so I use wrap-routes. Once I introduce wrap-routes into the equation, the ordering of my middleware gets rather messed up in a way I wouldn't expect!
Version: 1.5.1
I would expect:
All my non wrap-routes middleware to execute first and then if the route matches, my wrap-routes middleware to execute in the same order as they were defined. However, instead the wrap-routes middleware actually execute in the opposite order compared to the order my other middleware execute in.
I have a small test case to reproduce:
When hitting the route, the above logs:
I would expect:
Is this intentional behavior? Would you consider changing this? (I realize that changing ordering of execution of middleware may have subtle downstream impacts).