with-middleware -> wrap-middleware. uses compojure's wrap-routes now
this fixes problems where middleware could be run even if the wrapped routes did not match the request (depended on scoping, e.g. nesting in a context could limit this, but was not perfect).
This commit is contained in:
parent
ad8401f88c
commit
da94d5fd75
|
@ -31,11 +31,11 @@
|
||||||
|
|
||||||
;; -----------------------------------------------------------------------------
|
;; -----------------------------------------------------------------------------
|
||||||
|
|
||||||
(defmacro with-middleware
|
(defmacro wrap-middleware
|
||||||
"Applies a sequence of middleware functions to a series of routes wrapped
|
"Applies middleware to a handler. Intended to be used to wrap a subset of
|
||||||
by this macro. For best results, use _within_ a compojure.core/context
|
Compojure routes with middleware. The middleware is only run if one of the
|
||||||
call. Remember that middleware will be applied in the reverse order
|
routes being wrapped is matched against the current request."
|
||||||
that it is specified in."
|
[handler & middlewares]
|
||||||
[middlewares & routes]
|
(let [middleware-forms (map #(concat '(compojure.core/wrap-routes) %) middlewares)]
|
||||||
`(-> (compojure.core/routes ~@routes)
|
`(-> ~handler
|
||||||
~@middlewares))
|
~@middleware-forms)))
|
||||||
|
|
Reference in a new issue