Created
October 25, 2010 06:31
-
-
Save mmcgrana/644502 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; "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}] | |
(cond | |
(.startsWith uri "/blog") | |
(blog-app (in-context req "/blog")) | |
(.startsWith uri "/forum") | |
(forum-app (in-context req "/forum")) | |
:else | |
(core-app (in-context req "")))) | |
; extract the pattern | |
(defn mount [mount-spec] | |
(fn [{:keys [uri] :as req}] | |
(some | |
(fn [[context app]] | |
(if (.startsWith uri context) | |
(app (in-context req context)))) | |
mount-spec))) | |
; mountable apps in current ring architecture | |
(def app | |
(mount | |
[["/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