diff --git a/backend/src/app/auth/oidc.clj b/backend/src/app/auth/oidc.clj index 39572bb18..258d6c142 100644 --- a/backend/src/app/auth/oidc.clj +++ b/backend/src/app/auth/oidc.clj @@ -515,7 +515,7 @@ [_ {:keys [executor session] :as cfg}] (let [cfg (update cfg :provider d/without-nils)] ["" {:middleware [[(:middleware session)] - [hmw/with-promise-async executor] + [hmw/with-dispatch executor] [hmw/with-config cfg] [provider-lookup] ]} diff --git a/backend/src/app/http.clj b/backend/src/app/http.clj index 7bef64e78..92b986ca6 100644 --- a/backend/src/app/http.clj +++ b/backend/src/app/http.clj @@ -10,7 +10,7 @@ [app.common.logging :as l] [app.common.transit :as t] [app.http.errors :as errors] - [app.http.middleware :as middleware] + [app.http.middleware :as mw] [app.metrics :as mtx] [app.worker :as wrk] [clojure.spec.alpha :as s] @@ -144,12 +144,12 @@ (defmethod ig/init-key ::router [_ {:keys [ws session metrics assets feedback] :as cfg}] (rr/router - [["" {:middleware [[middleware/server-timing] - [middleware/format-response] - [middleware/params] - [middleware/parse-request] - [middleware/errors errors/handle] - [middleware/restrict-methods]]} + [["" {:middleware [[mw/server-timing] + [mw/format-response] + [mw/params] + [mw/parse-request] + [mw/errors errors/handle] + [mw/restrict-methods]]} ["/metrics" {:handler (:handler metrics)}] ["/assets" {:middleware [(:middleware session)]} @@ -167,7 +167,7 @@ :handler ws :allowed-methods #{:get}}] - ["/api" {:middleware [[middleware/cors] + ["/api" {:middleware [[mw/cors] [(:middleware session)]]} ["/audit/events" {:handler (:audit-handler cfg) :allowed-methods #{:post}}] @@ -176,4 +176,3 @@ (:doc-routes cfg) (:oidc-routes cfg) (:rpc-routes cfg)]]])) - diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index 11a29f892..a7f936b4c 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -379,17 +379,20 @@ (defmethod ig/init-key ::routes [_ {:keys [session pool executor] :as cfg}] - ["/dbg" {:middleware [[(:middleware session)] - [with-authorization pool] - [mw/with-promise-async executor] - [mw/with-config cfg]]} - ["" {:handler index-handler}] - ["/health" {:handler health-handler}] - ["/changelog" {:handler changelog-handler}] - ;; ["/error-by-id/:id" {:handler error-handler}] - ["/error/:id" {:handler error-handler}] - ["/error" {:handler error-list-handler}] - ["/file/export" {:handler export-handler}] - ["/file/import" {:handler import-handler}] - ["/file/data" {:handler file-data-handler}] - ["/file/changes" {:handler file-changes-handler}]]) + [["/readyz" {:middleware [[mw/with-dispatch executor] + [mw/with-config cfg]] + :handler health-handler}] + ["/dbg" {:middleware [[(:middleware session)] + [with-authorization pool] + [mw/with-dispatch executor] + [mw/with-config cfg]]} + ["" {:handler index-handler}] + ["/health" {:handler health-handler}] + ["/changelog" {:handler changelog-handler}] + ;; ["/error-by-id/:id" {:handler error-handler}] + ["/error/:id" {:handler error-handler}] + ["/error" {:handler error-list-handler}] + ["/file/export" {:handler export-handler}] + ["/file/import" {:handler import-handler}] + ["/file/data" {:handler file-data-handler}] + ["/file/changes" {:handler file-changes-handler}]]]) diff --git a/backend/src/app/http/middleware.clj b/backend/src/app/http/middleware.clj index 95c3a6b17..d0194d24f 100644 --- a/backend/src/app/http/middleware.clj +++ b/backend/src/app/http/middleware.clj @@ -195,8 +195,9 @@ {:name ::restrict-methods :compile compile-restrict-methods}) -(def with-promise-async - {:compile +(def with-dispatch + {:name ::with-dispatch + :compile (fn [& _] (fn [handler executor] (fn [request respond raise] @@ -206,7 +207,8 @@ (p/catch raise)))))}) (def with-config - {:compile + {:name ::with-config + :compile (fn [& _] (fn [handler config] (fn diff --git a/backend/src/app/http/session.clj b/backend/src/app/http/session.clj index f3e401641..18d02d8ed 100644 --- a/backend/src/app/http/session.clj +++ b/backend/src/app/http/session.clj @@ -230,13 +230,12 @@ (handler request respond raise) :else - (let [request (-> request - (assoc :profile-id (:profile-id session)) - (assoc :session-id (:id session))) - respond (cond-> respond - (renew-session? session) - (wrap-respond session))] - + (let [request (-> request + (assoc :profile-id (:profile-id session)) + (assoc :session-id (:id session))) + respond (cond-> respond + (renew-session? session) + (wrap-respond session))] (handler request respond raise)))))) (catch Throwable cause diff --git a/exporter/src/app/http.cljs b/exporter/src/app/http.cljs index 062191169..e38a08d53 100644 --- a/exporter/src/app/http.cljs +++ b/exporter/src/app/http.cljs @@ -124,6 +124,16 @@ (let [token (.get ^js cookies cookie-name)] (handler (cond-> exchange token (assoc :request/auth-token token)))))) +(defn- wrap-health + "Add /healthz entry point intercept." + [handler] + (fn [{:keys [:request/path] :as exchange}] + (if (= path "/readyz") + (assoc exchange + :response/status 200 + :response/body "OK") + (handler exchange)))) + (defn- create-adapter [handler] (fn [req res] @@ -149,6 +159,7 @@ (defn init [] (let [handler (-> handlers/handler + (wrap-health) (wrap-auth "auth-token") (wrap-response-format) (wrap-params)