title: Compojure redirect
body: <p>I have the following compojure rootes</p>
  
  <pre><code>   (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"))
  </code></pre>
  
  <p>And I wrap them with the following handlers    </p>
  
  <pre><code>  (defn default-handler [routes]
      (wrap-defaults routes
                     (-&gt; site-defaults
                         (assoc-in
                          [:security :anti-forgery] false))))
  
    (def http-handler
      (-&gt; (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}))
  </code></pre>
  
  <p>I run a ring server behind and nginx reverse proxy. The problem I face is with the redirection. I cannot properly redirect from compojure roots. Every redirection adds the hole address to the root path. For instance 
  <a href="http://79.137.xx.xxx/test" rel="nofollow noreferrer">http://79.137.xx.xxx/test</a>  redirects to  <a href="http://79.137.xx.xxx%2C79.137.xx.xxx/login" rel="nofollow noreferrer">http://79.137.xx.xxx%2C79.137.xx.xxx/login</a> instead of <a href="http://79.137.xx.xxx/login" rel="nofollow noreferrer">http://79.137.xx.xxx/login</a>
  To redirect from "/" to a uri one can add the following middlewere</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And this works but I would prefer to avoid adding a middlewere for each redirection path</p>