Skip to content
Snippets Groups Projects
Commit 9d91ef5b authored by Allen Gilliland's avatar Allen Gilliland
Browse files

update the delivery of the index.html page so that we can inject values into it dynamically.

parent 14123646
Branches
Tags
No related merge requests found
......@@ -2,8 +2,28 @@
(:require [compojure.core :refer [context defroutes GET]]
[compojure.route :as route]
[ring.util.response :as resp]
[stencil.core :as stencil]
[metabase.api.routes :as api]
[metabase.setup :as setup]))
[metabase.setup :as setup]
[metabase.util :as u]))
(defn- load-index-template
"Slurp in the Metabase index.html file as a `String`"
[]
(slurp (clojure.java.io/resource "frontend_client/index.html")))
(def load-index
"Memoized version of `load-index-template`"
;(memoize load-index-template)
load-index-template)
(def date-format-rfc2616
"Java SimpleDateFormat representing rfc2616 style date used in http headers."
"EEE, dd MMM yyyy HH:mm:ss zzz")
(def index-page-vars
"Static values that we inject into the index.html page via Mustache."
{:ga_code "UA-60817802-1"})
;; Redirect naughty users who try to visit a page other than setup if setup is not yet complete
(let [redirect-to-setup? (fn [{:keys [uri]}]
......@@ -11,7 +31,9 @@
(not (re-matches #"^/setup/.*$" uri))))
index (fn [request]
(if (redirect-to-setup? request) (resp/redirect (format "/setup/init/%s" (setup/token-value)))
(resp/resource-response "frontend_client/index.html")))]
(-> (resp/response (stencil/render-string (load-index) index-page-vars))
(resp/content-type "text/html")
(resp/header "Last-Modified" (u/now-with-format date-format-rfc2616)))))]
(defroutes routes
(GET "/" [] index) ; ^/$ -> index.html
(GET "/favicon.ico" [] (resp/resource-response "frontend_client/favicon.ico"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment