summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2014-05-19 11:24:54 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2014-05-19 11:24:54 +1000
commit92ce6a23354422ba0a87d2d64548b83e0da8737b (patch)
treeb405472783f6866104d6b7dcea59c91ce54993de /src
parentb3e639fae5e93cab62c139c7fdd856c3b1545b98 (diff)
Make the URL a full URL, with the HOST specified too
Diffstat (limited to 'src')
-rw-r--r--src/abra/core.clj10
1 files 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))))))