Skip to content

Commit ed5a2c9

Browse files
author
dnolen
committed
always serve the established set of files, add .png, issue reported by Kovas Boguta
1 parent 6546749 commit ed5a2c9

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/main/clojure/cljs/repl/browser.clj

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
(def ^:dynamic ordering nil)
2525
(def ^:dynamic es nil)
2626

27+
(def ext->mime-type
28+
{".html" "text/html"
29+
".css" "text/css"
30+
31+
".jpg" "image/jpeg"
32+
".png" "image/png"
33+
".gif" "image/gif"
34+
35+
".js" "text/javascript"
36+
".cljs" "text/x-clojure"
37+
".cljc" "text/x-clojure"
38+
".map" "application/json"})
39+
2740
(defn- set-return-value-fn
2841
"Save the return value function which will be called when the next
2942
return value is received."
@@ -84,16 +97,8 @@
8497
local-path)]
8598
(if local-path
8699
(server/send-and-close conn 200 (slurp local-path)
87-
(condp #(.endsWith %2 %1) path
88-
".html" "text/html"
89-
".css" "text/css"
90-
".html" "text/html"
91-
".jpg" "image/jpeg"
92-
".js" "text/javascript"
93-
".cljs" "text/x-clojure"
94-
".cljc" "text/x-clojure"
95-
".map" "application/json"
96-
".png" "image/png"
100+
(if (some #(.endsWith path %) (keys ext->mime-type))
101+
(get ext->mime-type path)
97102
"text/plain"))
98103
(server/send-404 conn path)))
99104
(server/send-404 conn path)))
@@ -105,14 +110,7 @@
105110

106111
(server/dispatch-on :get
107112
(fn [{:keys [path]} _ _]
108-
(or
109-
(= path "/")
110-
(.endsWith path ".js")
111-
(.endsWith path ".cljc")
112-
(.endsWith path ".cljs")
113-
(.endsWith path ".map")
114-
(.endsWith path ".html")
115-
(.endsWith path ".css")))
113+
(or (= path "/") (some #(.endsWith path %) (keys ext->mime-type))))
116114
send-static)
117115

118116
(defmulti handle-post (fn [m _ _ ] (:type m)))

0 commit comments

Comments
 (0)