Created
February 18, 2015 19:22
-
-
Save Kungi/9bb1cdb88df9ea889300 to your computer and use it in GitHub Desktop.
wrap-strip-context-path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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