Skip to content

Instantly share code, notes, and snippets.

@Kungi
Created February 18, 2015 19:22
Show Gist options
  • Save Kungi/9bb1cdb88df9ea889300 to your computer and use it in GitHub Desktop.
Save Kungi/9bb1cdb88df9ea889300 to your computer and use it in GitHub Desktop.
wrap-strip-context-path
(defn wrap-strip-context-path
"Strip context-path from all routes"
[handler]
(fn [in-req]
(cond (empty? @config/context-paths)
(handler in-req)
:else
(let [context (first (filter (complement nil?)
(map #(re-find (re-pattern %)
(:uri in-req))
@config/context-paths)))
req (if (nil? context)
in-req
(assoc in-req
:uri (clojure.string/replace-first (:uri in-req)
(re-pattern context)
"")
:context context))]
(timbre/trace "Stripping context path" context)
(timbre/trace "From" (:uri in-req))
(timbre/trace "To" (:uri req))
(timbre/trace "The request is:" req)
(binding [config/current-context (or context "")]
(handler req))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment