From 92ce6a23354422ba0a87d2d64548b83e0da8737b Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 19 May 2014 11:24:54 +1000 Subject: Make the URL a full URL, with the HOST specified too --- src/abra/core.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/abra/core.clj b/src/abra/core.clj index 19d85cd..19e4990 100644 --- a/src/abra/core.clj +++ b/src/abra/core.clj @@ -4,6 +4,7 @@ [clojure.string :as string])) (def ^:private ^:dynamic *lookup-route* nil) +(def ^:private ^:dynamic *request* nil) (def ^:private ^:dynamic *root* nil) (defn ^:private deref-if-var [arg] @@ -23,6 +24,7 @@ [handler & [root]] (fn [request] (binding [*lookup-route* (->> handler deref-if-var meta ::lookup) + *request* request *root* (or root "")] (handler request)))) @@ -127,9 +129,13 @@ [route & arg-values] (let [spec (*lookup-route* [route arg-values]) {:keys [uri type args]} spec - root-path *root*] + root-path *root* + prefix (if *request* + (str (name (:scheme *request*)) "://" + (get-in *request* [:headers "host"])))] (if spec - (str root-path + (str prefix + root-path (reduce (fn [string [name val]] (clojure.string/replace string (str name) (str val))) uri (map vector args arg-values)))))) -- cgit v1.2.3