From 0b1b85592fa8acfacaf3d389935d189ddbb844a9 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Tue, 7 May 2024 16:51:32 -0500 Subject: [PATCH] (maint) pdb-core-routes: return a GET for /, not a bare handler fn Return a compojure GET route for "/" rather than a context wrapping a plain clojure function. Before this change the "/" context handler was being selected for all routes, so all routes returned the dashboard redirection. This was likely caused by the recent clj-parent upgrade that pulled compojure to a much newer version. cf. https://github.com/weavejester/compojure/wiki/Nesting-routes 6416f22a26f5f238033cd9f93bcbd55e47ca6833 --- src/puppetlabs/puppetdb/pdb_routing.clj | 41 +++++++++---------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/puppetlabs/puppetdb/pdb_routing.clj b/src/puppetlabs/puppetdb/pdb_routing.clj index d68667c2a0..6a2016a3f8 100644 --- a/src/puppetlabs/puppetdb/pdb_routing.clj +++ b/src/puppetlabs/puppetdb/pdb_routing.clj @@ -28,33 +28,20 @@ {:status 503 :body (tru "PuppetDB is currently down. Try again later.")}))) -(defn wrap-with-context [uri route] - (compojure/context uri [] route)) - -(defn pdb-core-routes [defaulted-config get-shared-globals enqueue-command-fn - query-fn clean-fn delete-node-fn] - (let [db-cfg #(select-keys (get-shared-globals) [:scf-read-db])] - (map #(apply wrap-with-context %) - (partition - 2 - ;; The remaining get-shared-globals args are for wrap-with-globals. - ["/" (fn [req] - (->> req - rreq/request-url - (format "%s/dashboard/index.html") - rr/redirect)) - "/dashboard" (dashboard/build-app dashboard/default-meter-defs) - "/meta" (meta/build-app db-cfg defaulted-config) - "/cmd" (cmd/command-app get-shared-globals - enqueue-command-fn - (conf/reject-large-commands? defaulted-config) - (conf/max-command-size defaulted-config)) - "/query" (server/build-app get-shared-globals) - "/admin" (admin/build-app enqueue-command-fn - query-fn - db-cfg - clean-fn - delete-node-fn)])))) +(defn pdb-core-routes + [defaulted-config get-shared-globals enqueue-command-fn query-fn clean-fn delete-node-fn] + (let [db-cfg #(select-keys (get-shared-globals) [:scf-read-db]) + context #(compojure/context %1 [] %2)] + [(compojure/GET "/" req + (rr/redirect (str (rreq/request-url req) "/dashboard/index.html"))) + (context "/dashboard" (dashboard/build-app dashboard/default-meter-defs)) + (context "/meta" (meta/build-app db-cfg defaulted-config)) + (context "/cmd" (cmd/command-app get-shared-globals enqueue-command-fn + (conf/reject-large-commands? defaulted-config) + (conf/max-command-size defaulted-config))) + (context "/query" (server/build-app get-shared-globals)) + (context "/admin" (admin/build-app enqueue-command-fn query-fn db-cfg clean-fn + delete-node-fn))])) (defn pdb-app [root maint-mode-fn app-routes] (compojure/context root []