Skip to content

Instantly share code, notes, and snippets.

@mmcgrana mmcgrana/path.clj
Created Oct 25, 2010

What would you like to do?
;; "to help support nested routes and mounted applications within applications"
; we have some sub-apps we want to be active at different contexts
(defn blog-app [req] ...)
(defn forum-app [req] ...)
(defn core-app [req] ...)
; a heler function for setting up context keys
(defn in-context [context req]
(assoc req
:context context
:path-info (.substring (:uri req) (.length context))))
; naive implementation
(defn app [{:keys [uri] :as req}]
(.startsWith uri "/blog")
(blog-app (in-context req "/blog"))
(.startsWith uri "/forum")
(forum-app (in-context req "/forum"))
(core-app (in-context req ""))))
; extract the pattern
(defn mount [mount-spec]
(fn [{:keys [uri] :as req}]
(fn [[context app]]
(if (.startsWith uri context)
(app (in-context req context))))
; mountable apps in current ring architecture
(def app
[["/blog" blog-app]
["/forum" forum-app]
["" core-app]]))
;; "application deployment in context"
; our app
(defn app [req] ...)
; middleware to set up context keys
(defn wrap-context [handler context]
(fn [req]
(handler (in-context req context))))
; our app deployed in specified context
(def deployed-app
(-> app
(wrap-context "/app/context")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.