ring

chadhs 2017-10-27T13:35:37.000203Z

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

chadhs 2017-10-27T13:36:56.000407Z

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.

2017-10-27T18:53:32.000082Z

@chadhs What route in particular isn’t working?

chadhs 2017-10-27T18:54:49.000168Z

just the default route itself

chadhs 2017-10-27T18:55:26.000551Z

@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

chadhs 2017-10-27T18:56:57.000181Z

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 😞

2017-10-27T18:58:15.000024Z

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

chadhs 2017-10-27T18:59:01.000009Z

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

2017-10-27T18:59:34.000285Z

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

2017-10-27T19:00:12.000706Z

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

2017-10-27T19:00:55.000034Z

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

chadhs 2017-10-27T19:02:43.000550Z

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

chadhs 2017-10-27T19:03:55.000131Z

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

2017-10-27T19:04:46.000221Z

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.

2017-10-27T19:07:41.000200Z

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

2017-10-27T19:08:02.000435Z

That’s more how I’d do it.

2017-10-27T19:08:19.000412Z

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

chadhs 2017-10-27T19:09:44.000557Z

much appreciated! gives me a good place to start