My ressources/public directory contain many subfolders and each one contain an index.html. How do I set the routes so that they watch for any GET ".../" path recursively and return the index.html without showing the file in the URL?
One way to do it is to explicitly set each route like below but I'm hoping to not need to define each path.
(GET "/" [] (resource-response "index.html" {:root "public"}))
(GET "/foo" [] (resource-response "foo/index.html" {:root "public"}))
...
A small modification to ring wrap-resources middleware will do the trick:
(defn wrap-serve-index-file
[handler root-path]
(fn [request]
(if-not (= :get (:request-method request))
(handler request)
(let [path (.substring (codec/url-decode (:uri request)) 1)
final-path (if (= \/ (or (last path) \/))
(str path "index.html")
path)]
(or (response/resource-response path {:root root-path})
(handler request))))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With