Skip to content

Commit

Permalink
properly fix dev-http push-state looking for nested indexes
Browse files Browse the repository at this point in the history
fixes #1064
  • Loading branch information
thheller committed Nov 30, 2022
1 parent 9f4365c commit 7e8b27f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
10 changes: 10 additions & 0 deletions out/demo-browser/public/foo/index.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>foo index</title>
</head>
<body>
asked for foo, got foo
</body>
</html>
27 changes: 22 additions & 5 deletions src/main/shadow/http/push_state.clj
Expand Up @@ -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
Expand Down

0 comments on commit 7e8b27f

Please sign in to comment.