Permalink
Browse files

Merge pull request #132 from oliyh/master

Adding routing to allow base-url to work with standalone app
  • Loading branch information...
2 parents 8ab53c3 + 8bd007d commit 744780c466837ebb920cfe22c45c6da1140f592b @Raynes Raynes committed Nov 12, 2012
Showing with 19 additions and 1 deletion.
  1. +13 −1 src/noir/server/handler.clj
  2. +6 −0 test/noir/test/core.clj
@@ -15,7 +15,8 @@
[noir.statuses :as statuses]
[noir.options :as options]
[noir.session :as session]
- [noir.validation :as validation]))
+ [noir.validation :as validation]
+ [clojure.string :as string]))
(defonce middleware (atom []))
(defonce wrappers (atom []))
@@ -65,6 +66,16 @@
handler
(seq @middleware)))
+(defn- wrap-base-url-routing [handler]
+ (fn [req]
+ (let [path-info (or (:path-info req)
+ (if-let [base-url (options/get :base-url)]
+ (string/replace-first (:uri req) base-url "")
+ (:uri req)))]
+ (handler (assoc req :path-info path-info)))))
+
+
+
;;***************************************************
;; Route packing
;;***************************************************
@@ -111,6 +122,7 @@
(binding [options/*options* (options/compile-options opts)]
(-> handler
(hiccup/wrap-base-url (options/get :base-url))
+ (wrap-base-url-routing)
(session/wrap-noir-flash)
(session/wrap-noir-session
(assoc-if {:store (options/get :session-store (memory-store session/mem))}
@@ -227,6 +227,12 @@
(has-status 200)
(has-body "<a href=\"/woohoo/hey\">link</a>"))))
+(deftest base-url-routing
+ (binding [options/*options* {:base-url "/woohoo"}]
+ (-> (send-request "/woohoo/base-url")
+ (has-status 200)
+ (has-body "<a href=\"/woohoo/hey\">link</a>"))))
+
(deftest jsonp
(-> (resp/jsonp "jsonp245" {:pinot "noir"})
(has-content-type "application/json; charset=utf-8")

0 comments on commit 744780c

Please sign in to comment.