Skip to content

Commit

Permalink
(maint) pdb-core-routes: return a GET for /, not a bare handler fn
Browse files Browse the repository at this point in the history
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
  6416f22
  • Loading branch information
rbrw committed May 7, 2024
1 parent 0f63fe0 commit 0b1b855
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/puppetlabs/puppetdb/pdb_routing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down

0 comments on commit 0b1b855

Please sign in to comment.