clojure - Ring/Compojure serving index.html in subfolders? -
my ressources/public
directory contain many subfolders , each 1 contain index.html. how set routes watch ".../" path recursively , return index.html without showing file in url?
one way explicitly set each route below i'm hoping not need define each path.
(get "/" [] (resource-response "index.html" {:root "public"})) (get "/foo" [] (resource-response "foo/index.html" {:root "public"})) ...
a small modification ring wrap-resources middleware 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))))))
Comments
Post a Comment