summaryrefslogtreecommitdiff
path: root/src/ruuter/core.cljc
diff options
context:
space:
mode:
authorAsko Nõmm <asko@omma.ee>2023-07-27 14:23:16 +0000
committerAsko Nõmm <asko@omma.ee>2023-07-27 14:23:16 +0000
commitd724906cf6ed789e2dcead20967ac6371367357a (patch)
tree58ea64bc5a0ce63e4c12a0b7117e0d3ae1c53db5 /src/ruuter/core.cljc
parentf096efe85f627490ecc7c19fb9423aa4fb3574ab (diff)
Release 1.3.4.
Diffstat (limited to 'src/ruuter/core.cljc')
-rw-r--r--src/ruuter/core.cljc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ruuter/core.cljc b/src/ruuter/core.cljc
index ec382ec..41201cc 100644
--- a/src/ruuter/core.cljc
+++ b/src/ruuter/core.cljc
@@ -3,6 +3,16 @@
[clojure.string :as string])
#?(:clj (:gen-class)))
+(defn deep-merge [& maps]
+ (letfn [(reconcile-keys [val-in-result val-in-latter]
+ (if (and (map? val-in-result)
+ (map? val-in-latter))
+ (merge-with reconcile-keys val-in-result val-in-latter)
+ val-in-latter))
+ (reconcile-maps [result latter]
+ (merge-with reconcile-keys result latter))]
+ (reduce reconcile-maps maps)))
+
(defn- path->regex-path
"Takes in a raw route `path` and turns it into a regex pattern to
match against the request URI."
@@ -105,8 +115,8 @@
; when using a function, you get the whole `req` and params
; with it as well.
(fn? response)
- (response (->> {:params (path+uri->path-params path uri)}
- (merge req)))
+ (response (-> {:params (path+uri->path-params path uri)}
+ (deep-merge req)))
; if by whatever reason we make it here it must mean the
; route is invalid, or doesn't exist, in which case we return
; an error message.