Skip to content

Commit

Permalink
Use Selmer templates to inject proxy path prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinqian00 committed Nov 21, 2024
1 parent c4959bd commit 740f803
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/main/lrsql/admin/interceptors/ui.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
(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."
[_]
(-> (resp/resource-response "public/admin/index.html")
(assoc-in [:headers "Content-Type"] "text/html")))
[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."
Expand Down
6 changes: 3 additions & 3 deletions src/main/lrsql/admin/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@
(ui/get-env inject-config))
:route-name :lrsql.admin.ui/get-env]
;; SPA routes
["/admin/ui" :get ui/get-spa
["/admin/ui" :get (ui/get-spa proxy-path)
:route-name :lrsql.admin.ui/main-path]
["/admin/ui/" :get ui/get-spa
["/admin/ui/" :get (ui/get-spa proxy-path)
:route-name :lrsql.admin.ui/slash-path]
["/admin/ui/*path" :get ui/get-spa
["/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)
Expand Down

0 comments on commit 740f803

Please sign in to comment.