Merge pull request #38 from DomainDrivenArchitecture/fix_resource_handling

fix rings & noirs resource upload & serve location
This commit is contained in:
Simon Brooke 2019-01-19 16:59:17 +00:00 committed by GitHub
commit 01982fdb11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 9 deletions

View file

@ -97,6 +97,7 @@
[xss-protection?]
(-> site-defaults
(update-in [:session] merge session-defaults)
(dissoc :static)
(assoc-in [:security :anti-forgery] xss-protection?)))

View file

@ -6,7 +6,12 @@
[selmer.middleware :refer [wrap-error-page]]
[prone.middleware :refer [wrap-exceptions]]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
[noir-exception.core :refer [wrap-internal-error]]))
[ring.middleware.file :refer [wrap-file]]
[ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.not-modified :refer [wrap-not-modified]]
[noir-exception.core :refer [wrap-internal-error]]
[smeagol.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
@ -44,7 +49,12 @@
(def production-middleware
[#(wrap-internal-error % :log (fn [e] (timbre/error e)))])
[#(wrap-internal-error % :log (fn [e] (timbre/error e)))
#(wrap-resource % "public")
#(wrap-file % util/content-dir
{:index-files? false :prefer-handler? true})
#(wrap-content-type %)
#(wrap-not-modified %)])
(defn load-middleware []

View file

@ -52,6 +52,7 @@
"Process `source-text` and save it to the specified `file-path`, committing it
to Git and finally redirecting to wiki-page."
[params suffix request]
(timbre/trace (format "process-source: '%s'" request))
(let [source-text (:src params)
page (:page params)
file-name (str page suffix)
@ -122,6 +123,7 @@
(defn wiki-page
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
[request]
(timbre/trace (format "wiki-page: '%s'" request))
(or
(show-sanity-check-error)
(let [params (keywordize-keys (:params request))
@ -163,7 +165,7 @@
"Render a form to allow the upload of a file."
[request]
(let [params (keywordize-keys (:params request))
data-path (str (io/resource-path) "/content/uploads/")
data-path (str util/content-dir "/content/uploads/")
git-repo (hist/load-or-init-repo util/content-dir)
upload (:upload params)
uploaded (if upload (ul/store-upload params data-path))

View file

@ -56,6 +56,8 @@
filename (:filename upload)]
(timbre/info
(str "Storing upload file: " upload))
(timbre/debug
(str "store-upload mv file: " tmp-file " to: " path filename))
(if tmp-file
(do
(.renameTo tmp-file