diff --git a/src/main/lrsql/admin/interceptors/ui.clj b/src/main/lrsql/admin/interceptors/ui.clj index d6a37bc9..4921d6e5 100644 --- a/src/main/lrsql/admin/interceptors/ui.clj +++ b/src/main/lrsql/admin/interceptors/ui.clj @@ -1,15 +1,25 @@ (ns lrsql.admin.interceptors.ui (:require [ring.util.response :as resp] + [selmer.parser :as selm-parser] [io.pedestal.interceptor :refer [interceptor]] [com.yetanalytics.lrs.pedestal.interceptor :as i] [lrsql.admin.interceptors.oidc :as oidc-i] [lrsql.init.localization :refer [custom-language-map]])) +(defn get-spa + "Handler function that returns the index.html file." + [path-prefix] + (fn [_] + (-> (selm-parser/render-file "public/admin/index.html" + {:prefix path-prefix}) + resp/response + (resp/content-type "text/html")))) + (defn admin-ui-redirect - "Handler function to redirect to the admin ui" + "Handler function to redirect to the admin UI." [path-prefix] (fn [_] - (resp/redirect (str path-prefix "/admin/index.html")))) + (resp/redirect (str path-prefix "/admin/ui")))) (defn get-env "Provide select config data to client upon request. Takes a map with static diff --git a/src/main/lrsql/admin/routes.clj b/src/main/lrsql/admin/routes.clj index abcb970b..1e4a8809 100644 --- a/src/main/lrsql/admin/routes.clj +++ b/src/main/lrsql/admin/routes.clj @@ -255,18 +255,23 @@ (defn admin-ui-routes [common-interceptors {:keys [proxy-path] :as inject-config}] - #{;; Redirect root to admin UI + #{["/admin/env" :get (conj common-interceptors + (ui/get-env inject-config)) + :route-name :lrsql.admin.ui/get-env] + ;; SPA routes + ["/admin/ui" :get (ui/get-spa proxy-path) + :route-name :lrsql.admin.ui/main-path] + ["/admin/ui/" :get (ui/get-spa proxy-path) + :route-name :lrsql.admin.ui/slash-path] + ["/admin/ui/*path" :get (ui/get-spa proxy-path) + :route-name :lrsql.admin.ui/sub-paths] + ;; SPA redirects ["/" :get (ui/admin-ui-redirect proxy-path) :route-name :lrsql.admin.ui/root-redirect] - ;; Redirect admin w/o slash to admin UI ["/admin" :get (ui/admin-ui-redirect proxy-path) - :route-name :lrsql.admin.ui/path-redirect] - ;; Redirect admin with slash to admin UI - ["/admin/" :get (ui/admin-ui-redirect proxy-path) :route-name :lrsql.admin.ui/slash-redirect] - ["/admin/env" :get (conj common-interceptors - (ui/get-env inject-config)) - :route-name :lrsql.admin.ui/get-env]}) + ["/admin/" :get (ui/admin-ui-redirect proxy-path) + :route-name :lrsql.admin.ui/slash-redirect-2]}) (defn admin-reaction-routes [common-interceptors jwt-secret jwt-leeway no-val-opts]