diff --git a/backend/src/app/http.clj b/backend/src/app/http.clj index f29c6388f..a3a0b36b8 100644 --- a/backend/src/app/http.clj +++ b/backend/src/app/http.clj @@ -98,7 +98,8 @@ (create-router cfg) (rr/routes (rr/create-resource-handler {:path "/"}) - (rr/create-default-handler)))] + (rr/create-default-handler)) + {:middleware [middleware/server-timing]})] (fn [request] (try (handler request) diff --git a/backend/src/app/http/middleware.clj b/backend/src/app/http/middleware.clj index 4aab02774..50cad7458 100644 --- a/backend/src/app/http/middleware.clj +++ b/backend/src/app/http/middleware.clj @@ -21,6 +21,16 @@ [ring.middleware.params :refer [wrap-params]] [ring.middleware.resource :refer [wrap-resource]])) +(defn wrap-server-timing + [handler] + (let [seconds-from #(float (/ (- (System/nanoTime) %) 1000000000))] + (fn [request] + (let [start (System/nanoTime) + response (handler request)] + (update response :headers + (fn [headers] + (assoc headers "Server-Timing" (str "total;dur=" (seconds-from start))))))))) + (defn wrap-parse-request-body [handler] (letfn [(parse-transit [body] @@ -130,3 +140,7 @@ (def keyword-params {:name ::keyword-params :compile (constantly wrap-keyword-params)}) + +(def server-timing + {:name ::server-timing + :compile (constantly wrap-server-timing)}) diff --git a/docker/devenv/files/nginx.conf b/docker/devenv/files/nginx.conf index 2227dc05a..04c8fd453 100644 --- a/docker/devenv/files/nginx.conf +++ b/docker/devenv/files/nginx.conf @@ -29,7 +29,7 @@ http { gzip_vary on; gzip_proxied any; - gzip_comp_level 6; + gzip_comp_level 3; gzip_buffers 16 8k; gzip_http_version 1.1;