noir-clojure/noir

redirect ignores context on app servers

Opened this issue · 0 comments

I notice there's a quirk in Noir when using redirects, if I'm deploying on an app server, such as Glassfish, the context root of the servlet will be determined by it and isn't known up front. Using wrap-base-url in the handler does not seem to affect noir.response.redirect, then it will try to redirect to the root URL instead of context + root.

The issue can be hacked around by redefining resolve-url

(defn fix-base-url [handler]
  (fn [request]
    (with-redefs [noir.options/resolve-url 
                  (fn [url] 
                    ;prepend context to the relative URLs
                    (if (.contains url "://") 
                      url (str (:context request) url)))]
      (handler request))))

but not by binding :base-url in noir.options as has been suggested here https://groups.google.com/forum/?fromgroups#!topic/clj-noir/KfJzndyJivc

(defn wrap-base-url
  [handler]
  (fn [request]
    (binding [noir.options/*options* (assoc noir.options/*options*
:base-url (:context request))]
      (handler request))))