Skip to content

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed May 11, 2021
1 parent 0bc08bf commit a234a8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src/webly/web/files.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[taoensso.timbre :refer [debug info error]]
[bidi.bidi :as bidi :refer [url-decode]]
[clojure.java.io :as io]
[ring.util.response :refer [file-response]]
[ring.middleware.content-type :refer (wrap-content-type)]
[ring.middleware.not-modified :refer (wrap-not-modified)]))
[ring.util.response :refer [file-response resource-response]]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.not-modified :refer [wrap-not-modified]]))

(defrecord FilesMaybe [options]
bidi/Matched
Expand All @@ -21,5 +21,26 @@
{:root (:dir options)}))
(wrap-content-type options)
(wrap-not-modified))))))
(unresolve-handler [this m]
(when (= this (:handler m)) "")))


; copied from bidi.
; but bidi forgot to wrap not modified
; https://github.com/juxt/bidi/issues/208


(defrecord ResourcesMaybe [options]
bidi/Matched
(resolve-handler [this m]
(let [path (url-decode (:remainder m))]
(when (not-empty path)
(when-let [res (io/resource (str (:prefix options) path))]
(assoc (dissoc m :remainder)
:handler (->
(fn [req] (resource-response (str (:prefix options) path)))
(wrap-content-type options)
(wrap-not-modified) ; awb99 hack
))))))
(unresolve-handler [this m]
(when (= this (:handler m)) "")))
3 changes: 2 additions & 1 deletion src/webly/web/resources.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@


#?(:clj (def resource-handler
(bidi.ring/->ResourcesMaybe {:prefix "public"}))
;(bidi.ring/->ResourcesMaybe {:prefix "public"})
(webly.web.files/->ResourcesMaybe {:prefix "public"}))
:cljs (def resource-handler :webly/resources))

#?(:clj (def file-handler
Expand Down

0 comments on commit a234a8c

Please sign in to comment.