From 7e8b27fe02401956fff294f7affe51d67f55f3c2 Mon Sep 17 00:00:00 2001
From: Thomas Heller
Date: Wed, 30 Nov 2022 10:26:27 +0100
Subject: [PATCH] properly fix dev-http push-state looking for nested indexes
fixes #1064
---
out/demo-browser/public/foo/index.html | 10 ++++++++++
src/main/shadow/http/push_state.clj | 27 +++++++++++++++++++++-----
2 files changed, 32 insertions(+), 5 deletions(-)
create mode 100644 out/demo-browser/public/foo/index.html
diff --git a/out/demo-browser/public/foo/index.html b/out/demo-browser/public/foo/index.html
new file mode 100644
index 000000000..6f9400020
--- /dev/null
+++ b/out/demo-browser/public/foo/index.html
@@ -0,0 +1,10 @@
+
+
+
+
+ foo index
+
+
+asked for foo, got foo
+
+
\ No newline at end of file
diff --git a/src/main/shadow/http/push_state.clj b/src/main/shadow/http/push_state.clj
index 2f421c5fd..b37cdcd13 100644
--- a/src/main/shadow/http/push_state.clj
+++ b/src/main/shadow/http/push_state.clj
@@ -18,17 +18,34 @@
headers
(get http-config :push-state/headers {"content-type" "text/html; charset=utf-8"})
+ ;; "/foo/" into "/foo"
+ ;; "/" into ""
+ uri
+ (if (str/ends-with? uri "/")
+ (subs uri 0 (-> uri (count) (dec)))
+ uri)
+
+ locations-to-test
+ (-> []
+ ;; for request going to "/foo" and http-root "public"
+ ;; checking "public/foo/index.html"
+ (into (map #(str % "/" uri "/" index-name)) http-roots)
+ ;; and then "public/index.html"
+ (into (map #(str % "/" index-name) http-roots)))
+
index-file
(reduce
- (fn [_ http-root]
- (if (str/starts-with? http-root "classpath:")
- (when-some [rc (io/resource (str (subs http-root 10) "/" index-name))]
+ (fn [_ file-to-test]
+ (if (str/starts-with? file-to-test "classpath:")
+ ;; drop classpath: and check for resources
+ (when-some [rc (io/resource (subs file-to-test 10))]
(reduced rc))
- (let [file (io/file http-root index-name)]
+ ;; check actual file via fs
+ (let [file (io/file file-to-test)]
(when (and file (.exists file))
(reduced file)))))
nil
- http-roots)]
+ locations-to-test)]
(if-not index-file
;; FIXME: serve some kind of default page instead