Open Akeboshiwind opened 5 months ago
:pre-middleware
and :post-middleware
:middleware
merge/concat onto :post-middleware
It would look something like this:
(def app
(defaults/make-app routes {:pre-middleware [random-select-middleware]
:post-middleware [other-middleware]}))
Downsides:
:middleware
to always run before route selection:middleware
key to individual routesIt would look something like this:
(def routes
[[:selected? #'selected]
[(complement :selected?) {:handler #'not-selected
:middleware [other-middleware]}]])
; With sketched parent data
(def routes
[(constantly true) {:middleware [other-middleware]}
[:selected? #'selected]
[(complement :selected?) {:handler #'not-selected
:middleware [other-middleware]}]])
(def app
(defaults/make-app routes {:middleware [random-select-middleware]}))
Downsides:
Use interceptors? Not thought this through but they can re-order themselves right?
Downsides:
Deprecate defaults
and instead provide a template project.
Downsides:
Having mulled over these a bit and explored interceptors a bit more, I'm feeling Proposal 2
the most.
I.e:
:middleware
in defaults to run before route selection:middleware
key to individual routesMy thoughts are:
(def routes
[{:middleware [do-something]}
[admin? {:middleware [admin-middleware]}
["/private" #'private-handler]]
[(constantly true) {:middleware [public-middleware]}
["/public" #'public-handler]]])
Currently you can only add middleware after the routes are selected.
A case where this might be useful is adding some data to the request then routing based on that:
To use this middleware currently you have to build the stack yourself: