-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_utils.clj
24 lines (22 loc) · 1.04 KB
/
route_utils.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(ns lupapiste-commons.route-utils
(:require [clojure.string :as string]
[clojure.java.io :as io]))
(defonce index-response (atom nil))
(defn process-index-response [{:strs [git-commit]}]
(if @index-response
@index-response
(with-open [is (-> (io/resource "public/index.html")
(io/input-stream))]
(let [content (slurp is)
version (if git-commit (subs git-commit 0 7) "dev")
replaced-html (-> (string/replace content ".css" (str ".css?v=" version))
(string/replace ".js" (str ".js?v=" version)))
response {:status 200
:body replaced-html
:headers {"Content-Type" "text/html"
"Content-Length" (str (count replaced-html))
"Cache-Control" "no-cache, no-store, must-revalidate"
"Pragma" "no-cache"
"Expires" "0"}}]
(reset! index-response response)
response))))