Skip to content

redirect ignores context on app servers #120

@yogthos

Description

@yogthos

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))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions