Fork me on GitHub
#ring
<
2017-10-27
>
chadhs13:10:37

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 file

chadhs13:10:56

I’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.

weavejester18:10:32

@chadhs What route in particular isn’t working?

chadhs18:10:49

just the default route itself

chadhs18:10:26

@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

chadhs18:10:57

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 😞

weavejester18:10:15

@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.

chadhs18:10:01

interesting, where is my compojure code explicitly not using any content-type?

weavejester18:10:34

You’re returning the full response map; essentially saying “Don’t fill anything in, I’m going to take care of everything.”

weavejester19:10:12

If you return a string from Compojure, then it will turn it into a HTTP response with a HTML content-type, for example.

weavejester19:10:55

You’re also handling the request yourself, instead of getting Compojure to destructure it.

chadhs19:10:43

@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.

chadhs19:10:55

i was expecting route → handler → view and hiccup in the view is returning html output so was expecting it to render

weavejester19:10:46

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.

weavejester19:10:41

(defn build-list-routes [db]
  (routes
   (GET "/list/:list-id" [list-id :<< coerce/as-uuid]
     (view/list-page (model/get-list db list-id))))

weavejester19:10:02

That’s more how I’d do it.

weavejester19:10:19

Although I’m using Ataraxy more than Compojure these days.

chadhs19:10:44

much appreciated! gives me a good place to start