私は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"})))