-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Description
:compile'ing middleware takes a bit of effort around the internals if the compiler function would need the route path.
In my case, I have a logger middleware that would include the route path template (also available as :template in Match) in the log. This information is fixed at compile time, so it feels wasteful to extract it every request from the Match.
Workaround
Using a :compile like below (in the case of reitit.ring/router) injects the :path into the data passed into the compiler.
(defn compile-add-path
[[path data extra] opts]
(reitit.ring/compile-result [path (assoc data :path path) extra] opts))
Path is a special case because it's treated separately from the data. Documentation around :compile isn't that rich, so I think it'd be preferable to inject the path into route-data (rather than have people copy-paste a compiler function they don't understand)
Ramblurr