在 Clojure 中使用 compojure.route/not-found 时获取 http 请求
Getting the http request when using compojure.route/not-found in Clojure
我正在使用 Cloujre 的 Compojure 构建服务器。默认路由是compojure.route/not-found
,有没有办法获取到达此路由的请求?我想打印所有在那里结束的请求。
您可以使用这种方法:
(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...
我正在使用 Cloujre 的 Compojure 构建服务器。默认路由是compojure.route/not-found
,有没有办法获取到达此路由的请求?我想打印所有在那里结束的请求。
您可以使用这种方法:
(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...