diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index 0ea22e97..5fa0b40b 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -96,24 +96,26 @@ (fn ([request] (handler request)) ([request respond _] (respond (handler request))))) + trim-path (fn [& paths] (str/replace (apply str paths) "//" "/")) resource-response (fn [path] - (if-let [response (or (paths path) (response/resource-response path options))] + (if-let [response (or (paths (trim-path "/" path)) (response/resource-response path options))] (response/content-type response (mime-type/ext-mime-type path)))) - path-or-index-response (fn [path] + path-or-index-response (fn [path uri] (or (resource-response path) - (let [separator (if-not (str/ends-with? path "/") "/")] - (loop [[file & files] index-files] - (if file - (or (resource-response (str path separator file)) - (recur files))))))) + (loop [[file & files] index-files] + (if file + (let [path (trim-path path file)] + (if (resource-response path) + {:status 302 :headers {"Location" (trim-path uri "/" path)}} + (recur files))))))) handler (if path (fn [request] (let [uri (:uri request)] (if-let [path (if (>= (count uri) path-size) (subs uri path-size))] - (path-or-index-response path)))) + (path-or-index-response path uri)))) (fn [request] (let [path (-> request :path-params parameter)] - (or (path-or-index-response path) {:status 404}))))] + (or (path-or-index-response path path) {:status 404}))))] (create handler))))) (defn ring-handler diff --git a/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc b/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc index 019c00d1..137dbcb5 100644 --- a/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc +++ b/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc @@ -42,11 +42,11 @@ (update $ :root (fnil identity "swagger-ui")) (update $ :url (fnil identity "/swagger.json")) (update $ :config #(->> % (map mixed-case-key) (into {}))) - (assoc $ :paths {"conf.js" {:headers {"Content-Type" "application/javascript"} - :status 200 - :body (conf-js $)} - "config.json" {:headers {"Content-Type" "application/json"} - :status 200 - :body (config-json $)}}))] + (assoc $ :paths {"/conf.js" {:headers {"Content-Type" "application/javascript"} + :status 200 + :body (conf-js $)} + "/config.json" {:headers {"Content-Type" "application/json"} + :status 200 + :body (config-json $)}}))] (ring/routes (ring/create-resource-handler options))))))