我正在使用Cloujre的Compojure构建服务器。默认路由是compojure.route/not-found
,有没有办法获得到达此路由的请求?我想打印那些结束的请求。
答案 0 :(得分:1)
你可以使用这种方法:
(def handler (-> your-routes
wrap-my-request-middleware ;; it has to be in this order
...))
让我们在这里登录uri
(defn wrap-my-request-middleware
[handler]
(fn [request]
(let [response (handler request)]
(when (= 404 (:status response))
;; do whatever you like in here
(log/info (str "Request path: " (:uri request))))
response)));; fn needs to return reponse...