Clojure 为什么我的Ring中间件在请求中看不到:params映射?
我正在编写一个Clojure 为什么我的Ring中间件在请求中看不到:params映射?,clojure,compojure,ring,Clojure,Compojure,Ring,我正在编写一个Ring中间件,并使用Compojure。我希望我的中间件在:params映射中查看用户是否提供了特定的密钥。但是,在我的中间件函数中,请求映射不包含:params映射。在最后一个请求处理程序中,有一个:params映射。我认为,:params映射在我的自定义中间件之前没有设置它,但我不知道如何才能真正设置它 有什么想法吗 (ns localshop.handler (:use [ring.middleware.format-response :only [wrap-restf
Ring
中间件,并使用Compojure
。我希望我的中间件在:params映射中查看用户是否提供了特定的密钥。但是,在我的中间件函数中,请求映射不包含:params映射。在最后一个请求处理程序中,有一个:params
映射。我认为,:params
映射在我的自定义中间件之前没有设置它,但我不知道如何才能真正设置它
有什么想法吗
(ns localshop.handler
(:use [ring.middleware.format-response :only [wrap-restful-response]]
[compojure.core])
(:require [localshop.routes.api.items :as routes-api-items]
[localshop.middleware.authorization :as authorization]
[compojure.handler :as handler]))
;; map the route handlers
(defroutes app-routes
(context "/api/item" [] routes-api-items/routes))
;; define the ring application
(def app
(-> (handler/api app-routes)
(authorization/require-access-token)
(wrap-restful-response)))
上面是我的handler.clj文件,下面是中间件本身
(ns localshop.middleware.authorization)
(defn require-access-token [handler]
(fn [request]
(if (get-in request [:params :token])
(handler request)
{:status 403 :body "No access token provided"})))
我真的弄明白了。如果您调整代码的
(def app…
部分,使其与以下内容匹配,则此操作有效:
(def app
(-> app-routes
(wrap-restful-response)
(authorization/require-access-token)
(handler/api)))