From 473bed92df3a2c35a23613913501b53560621753 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 5 Jan 2022 18:34:18 -0500 Subject: [PATCH] remove wrap-base, just put the optional wrap-reload under http-server i don't _really_ want to encourage the use of wrap-base as i think it is usually the wrong place to add middleware to. instead adding a placeholder :middleware list to the reitit ring-handler as the intended alternative place for "global" middleware that needs to be applied regardless of a reitit route match --- .../simple_web_service/src/root_ns/core.clj | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/resources/leiningen/new/simple_web_service/src/root_ns/core.clj b/resources/leiningen/new/simple_web_service/src/root_ns/core.clj index 92847a6..c2ab140 100644 --- a/resources/leiningen/new/simple_web_service/src/root_ns/core.clj +++ b/resources/leiningen/new/simple_web_service/src/root_ns/core.clj @@ -131,15 +131,15 @@ coercion/coerce-request-middleware ; coercing request parameters multipart/multipart-middleware ; multipart ]}}) - (ring/routes - (ring/create-default-handler)))) -(defn wrap-base - [handler] - (as-> handler h - (if (:dev? config) (wrap-reload h) h) - ; TODO: other base middleware here - )) + (ring/routes + (ring/create-default-handler)) + + ; add any top-level middleware here that will be applied to the *entire* handler, + ; regardless of the route matched, if any. (most of the time you'd want to use + ; the :middleware list found above though...) + {:middleware []})) + ;; @@ -168,7 +168,8 @@ :or {port 8080 bind "0.0.0.0"}} (:http-server config) server (http-kit/run-server - (wrap-base #'handler) + (as-> #'handler h + (if (:dev? config) (wrap-reload h) h)) {:port port :ip bind :server-header nil