如何使用friend和bidi來包裝資源處理程序?用bidi包裝資源處理程序
我已經成功地讓OAuth的認證路線:
(defn auth-handler [request] (friend/authorize #{::user}
{:status 200
:body "a secret"}))
(def routes ["/" {true auth-handler}])
(def app (make-handler routes))
(web/run-dmc (-> app
var
(friend/authenticate
{:allow-anon? true
:workflows [(oauth/workflow
{:client-config client-config
:uri-config uri-config
:credential-fn credential-fn})]})
(wrap-resource "public")
(wrap-defaults site-defaults)
))
該工程對「/」路線,但我想,以確保一些資源,如果不首先驗證中達到。
這似乎是可能與friend/wrap-authorize
功能:
我最親密的嘗試工作的權威性包裹路線,但不匹配的非的/ dev /路線:
(def routes ["/" [["dev/" [[true (friend/wrap-authorize (resources {:prefix "dev/"}) #{::user})]]]
[true (resources {:prefix "public/"})]]])
(match-route routes "/dev/index.html")
=>
{:handler #object[cemerick.friend$wrap_authorize$fn__24411
0x2400d0be
"[email protected]"]}
;correct
(match-route routes "/index.html")
=>
nil
;not correct
我想我路由模式[true (resources {:prefix "public/"})]
的匹配部分是錯誤的,因爲當我將其更改爲:key
時,'index.html'確實匹配。
如何將非/ dev/*路線與公共資源相匹配?
謝謝你看看這個問題。我現在注意到我的代碼甚至不能用於開發/處理程序,或者至少不一致。我想我現在會轉換成compojure。我也對爲什麼我的(文件響應)和(資源響應)讓我的瀏覽器下載響應而不是在瀏覽器中加載它們感到困惑。 – bbs
是的,可悲的是沒有太多的例子可以遵循......悲傷,因爲它似乎是一個偉大的想法,但使它在真實情況下工作是艱難的。瀏覽器下載文件通常表示未設置內容類型標題(因爲缺少中間件或處理程序未返回響應)。 –