Created
January 25, 2025 01:07
-
-
Save camsaul/045b6e5dd9d8c82d3759bdfa116c2a90 to your computer and use it in GitHub Desktop.
Smart Lazy REST API Ring routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def routes-map | |
{"/action" (+auth (api.macros/lazy-ns-handler 'metabase.api.action)) | |
"/activity" (+auth (api.macros/lazy-ns-handler 'metabase.api.activity)) | |
"/alert" (+auth (api.macros/lazy-ns-handler 'metabase.api.alert)) | |
"/automagic-dashboards" (+auth (api.macros/lazy-ns-handler 'metabase.api.automagic-dashboards)) | |
"/bookmark" (+auth (api.macros/lazy-ns-handler 'metabase.api.bookmark)) | |
"/card" (+auth api.card/routes) | |
"/cards" (+auth (api.macros/lazy-ns-handler 'metabase.api.cards)) | |
"/cloud-migration" (+auth api.cloud-migration/routes) | |
"/collection" (+auth api.collection/routes) | |
"/channel" (+auth channel.api/channel-routes) | |
"/dashboard" (+auth api.dashboard/routes) | |
"/database" (+auth api.database/routes) | |
"/dataset" (+auth api.dataset/routes) | |
"/docs" api.docs/routes | |
"/email" (+auth channel.api/email-routes) | |
"/embed" (+message-only-exceptions api.embed/routes) | |
"/field" (+auth api.field/routes) | |
"/geojson" api.geojson/routes | |
"/google" (+auth api.google/routes) | |
"/ldap" (+auth api.ldap/routes) | |
"/login-history" (+auth api.login-history/routes) | |
"/model-index" (+auth api.model-index/routes) | |
"/native-query-snippet" (+auth api.native-query-snippet/routes) | |
"/notify" (+static-apikey sync.api/notify-routes) | |
"/permissions" (+auth api.permissions/routes) | |
"/persist" (+auth api.persist/routes) | |
"/premium-features" (+auth api.premium-features/routes) | |
"/preview_embed" (+auth api.preview-embed/routes) | |
"/public" (+public-exceptions api.public/routes) | |
"/pulse/unsubscribe" api.pulse.unsubscribe/routes | |
"/pulse" (+auth api.pulse/routes) | |
"/revision" (+auth api.revision/routes) | |
"/search" (+auth api.search/routes) | |
"/segment" (+auth api.segment/routes) | |
"/session" api.session/routes | |
"/cache" (+auth api.cache/routes) | |
"/setting" (+auth api.setting/routes) | |
"/setup" setup.api/routes | |
"/slack" (+auth api.slack/routes) | |
"/table" (+auth api.table/routes) | |
"/task" (+auth api.task/routes) | |
"/testing" (if (or (not config/is-prod?) | |
(config/config-bool :mb-enable-test-endpoints)) | |
api.testing/routes | |
(fn [_ respond _] (respond nil))) | |
"/tiles" (+auth api.tiles/routes) | |
"/timeline" (+auth api.timeline/routes) | |
"/timeline-event" (+auth api.timeline-event/routes) | |
"/user" (+auth api.user/routes) | |
"/user-key-value" (+auth api.user-key-value/routes) | |
"/api-key" (+auth api.api-key/routes) | |
"/util" api.util/routes}) | |
(defn smart-handler [request respond raise] | |
(if-let [[_match prefix rest-of-path] (re-find #"(^/[^\/]+)(/.*$)" (:path-info request))] | |
(if-let [handler (get routes-map prefix)] | |
(let [request' (assoc request :path-info rest-of-path)] | |
(handler request' respond raise)) | |
(respond nil)) | |
(respond nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment