weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.09k stars 256 forks source link

allow redirect to see base url #163

Closed dpsutton closed 7 years ago

dpsutton commented 7 years ago

Our site sits in tomcat along with some others, so it's reached at host/app. An app after a post should redirect back to host/app/. However,

(cc/POST "/New" [site]
    (do (c/compile-flow site)
        (c/deploy-flow site)
        (redirect "/")))

redirects us back to host/ which gives us an nginx error. Is there a way to redirect to a base url?

weavejester commented 7 years ago

You can get the current context by looking up the :context key in the request map.

dpsutton commented 7 years ago

thanks for the quick response, @weavejester. If i expect a param in this post request, how do i write the params vector ([site]) to get access to the parameter i was previously sending in as well as the request itself?

weavejester commented 7 years ago

[site :as {:keys [context]}] should do it, I believe. The :context key is set by Lein-Ring, if you're using that. There's also the :servlet-context-path key, which is just for the servlet context path, and that's set by Ring when compiling a handler into a servlet.