summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))))))