我有一个名为/account的端点,它提供用户信息(返回html)。
当未经授权的用户试图访问这个端点时,我需要能够重定向到login page,但是在解放器中,到目前为止我找到了post-redirect,这只是为了post methods。
我也需要重定向get methods,我如何实现这一点?
发布于 2017-04-07 09:31:34
我找到了一个解决办法,下面的代码就是其中的诀窍:
(defn account
[]
(resource :allowed-methods [:get]
:available-media-types ["text/html"]
:exists? (fn [_] false)
:existed? (fn [_] true)
:moved-temporarily? (fn [ctx] {:location "/redirected-path-or-url"})
:handle-ok (fn [ctx]
[:html ...])
:handle-exception (fn [_]
"Something went wrong")))或者您可以检查:authorized?并从:handle-unauthorized返回登录html,但我怀疑这是否是一个好做法。
https://stackoverflow.com/questions/43272348
复制相似问题