2

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

1 に答える 1

1

私は実際にこれを理解しました。これは、コードの一部を次のように調整すると機能(def app ... )します。

(def app
  (-> app-routes
      (wrap-restful-response)
      (authorization/require-access-token)
      (handler/api)))
于 2013-02-19T02:36:02.300 に答える