如何使用朋友和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函数中似乎是可能的:
我最近的尝试在auth包装的路由上工作,但在非/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
"cemerick.friend$wrap_authorize$fn__24411@2400d0be"]}
;correct
(match-route routes "/index.html")
=>
nil
;not correct我认为我与路由模式[true (resources {:prefix "public/"})]的匹配部分是错误的,因为当我将它更改为:key时,`index.html‘就匹配了。
如何将非/dev/*路由匹配到公共资源?
发布于 2016-03-09 04:46:24
这里的主要问题是资源路线应该是
["" (resources {:prefix "public/"})]空字符串而不是true。
文档确实声明:在模式匹配之后,路径的其余部分被添加到给定的前缀中。
但坦率地说,我认为这是相当令人惊讶的行为。
我在这里做了一个最小的示例项目,它成功地路由了/index.html https://github.com/timothypratley/bidi-resources
值得注意的是,请求/index.html2会导致异常,这与我所期望的完全不同。我本来想要404的。o_O
我非常喜欢ClojureScript中的bidi,但到目前为止,我发现它在服务器端是一项艰难的工作.我理解为什么true不能工作的方法是用我自己的版本覆盖参考资料定义,输出输入,并看到:remainder是空的。
https://stackoverflow.com/questions/35875008
复制相似问题