I’m having an odd issue. I’m using ring, compojure, and hiccup together. my site renders fine when i’m using
(-> app
...
(wrap-resource "static")
wrap-file-info
wrap-web-jars)
however if i replace wrap-file-info with
wrap-content-type
wrap-not-modified
loading my site downloads the rendered html as an Unknown.dms
fileI’d like to refactor and replace the deprecated wrap-file-info
but seem to be stuck at this point; looking for a little push to help me solve this thanks.
@chadhs What route in particular isn’t working?
just the default route itself
@weavejester it’s a toy app i’m using to learn and i have it on github https://github.com/chadhs/listopia/blob/master/src/listopia/core.clj
was hoping replacing wrap-file-info
with wrap-content-type
and wrap-not-modified
would be a no-op but results in the behavior i mentioned above 😞
@chadhs Your code is telling Compojure to explicitly not use any content-type, and wrap-content-type
works off the file extension, so that will default to application/octet-stream
.
interesting, where is my compojure code explicitly not using any content-type?
You’re returning the full response map; essentially saying “Don’t fill anything in, I’m going to take care of everything.”
If you return a string from Compojure, then it will turn it into a HTTP response with a HTML content-type, for example.
You’re also handling the request yourself, instead of getting Compojure to destructure it.
@weavejester clearly i need to look at some examples; i don’t understand how this is working nearly as well as I thought I did.
i was expecting route → handler → view and hiccup in the view is returning html output so was expecting it to render
Right, but you need to tell it that it’s HTML output. If you just return a string, then Compojure will assume it’s HTML. If you return a full response map, it assumes you know what you’re doing.
(defn build-list-routes [db]
(routes
(GET "/list/:list-id" [list-id :<< coerce/as-uuid]
(view/list-page (model/get-list db list-id))))
That’s more how I’d do it.
Although I’m using Ataraxy more than Compojure these days.
much appreciated! gives me a good place to start