Closed rutchkiwi closed 4 years ago
You can write some middleware that passes :compojure/route
to the response map, then use wrap-routes
to get it in the right position. So something like:
(defn wrap-response-route-info [handler]
(fn [request]
(assoc (handler request) :compojure/route (:compojure/route request))))
(def app
(wrap-routes handler wrap-response-route-info)
Ah, how elegant! I see I had not really understood how wrap-routes works.
Thank you so much for the quick reply! :)
First of all, thanks for this great library!
I would like to access the
:compojure/route
object in a ring middleware "outside" of defroutes.This would allow me to automatically log, and get automatically get request timings on a route level.
For example:
(not actually working code but illustrates my point)
Once I have done that, I'd be able to automatically show the average response times of different routes by some sql like
Note that I want the average time of all product requests, not separate entries for each product.
I believe this could be accomplished by modifying this line: https://github.com/weavejester/compojure/blob/bb2fcc7ffdc910555d24ff64a8e7ffacb2c1c478/src/compojure/core.clj#L137
into something like this:
Would you be open to a PR like this? Or is there perhaps already a way to accomplish this withoutout any changes to compojure?