我有以下compojure rootes
(defroutes app-routes
(GET "/login" [] (views/login))
(POST "/index.html" req (auth/do-login req))
(GET "/main" req (views/main req))
(GET "/test" [] (redirect "/login"))
(not-found "Not Found"))
我用以下处理程序包装它们
(defn default-handler [routes]
(wrap-defaults routes
(-> site-defaults
(assoc-in
[:security :anti-forgery] false))))
(def http-handler
(-> (default-handler app-routes)
(wrap-stacktrace)
(wrap-authentication backend)
(wrap-authorization backend)
(wrap-session)
(wrap-params)
(wrap-with-logger)))
(defn -main []
(run-jetty http-handler {:port 8000 :join? false}))
我在后面运行一个响铃服务器和nginx反向代理。我面临的问题是重定向。我不能正确地从compojure根重定向。每次重定向都会将孔地址添加到根路径。例如 http://79.137.xx.xxx/test重定向到http://79.137.xx.xxx%2C79.137.xx.xxx/login而不是http://79.137.xx.xxx/login 从" /"重定向对于一个uri,可以添加以下中间
2 (defn redirect* [handler uri]
33 (fn [request]
34 ¦ (let [k (if (contains? request :path-info)
35 ¦ ¦ ¦ ¦ ¦ ¦ ¦ :path-info :uri) v (get request k)]
36 ¦ ¦ (if (re-find #"/$" v)
37 ¦ ¦ ¦ (ring.util.response/redirect uri)
38 ¦ ¦ ¦ (handler request)))))
39
这有效但我宁愿避免为每个重定向路径添加中间件