This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-18
Channels
- # bangalore-clj (1)
- # beginners (60)
- # boot (98)
- # cider (8)
- # clojure (158)
- # clojure-dusseldorf (16)
- # clojure-france (3)
- # clojure-hamburg (2)
- # clojure-mke (2)
- # clojure-russia (11)
- # clojure-serbia (1)
- # clojure-spec (123)
- # clojure-uk (59)
- # clojurescript (44)
- # code-reviews (16)
- # community-development (51)
- # core-async (46)
- # cryogen (1)
- # cursive (9)
- # datascript (5)
- # datomic (36)
- # emacs (3)
- # events (12)
- # hoplon (57)
- # jobs (1)
- # juxt (3)
- # klipse (55)
- # lein-figwheel (3)
- # leiningen (5)
- # luminus (3)
- # off-topic (8)
- # om (75)
- # om-next (9)
- # onyx (17)
- # pedestal (7)
- # portland-or (3)
- # proton (36)
- # protorepl (6)
- # re-frame (3)
- # reagent (33)
- # remote-jobs (1)
- # ring (23)
- # ring-swagger (2)
- # rum (1)
- # specter (1)
- # untangled (36)
- # yada (11)
@seancornfield I have my application startup using a ring plugin with a ring handler provided in project.clj ...
but I think now I'm just going to take the sente base application (that works with sockets and httpkit) and just superimpose my application-thus-far onto it. easier than trying to reason about layers of web intestine imho
That would be my recommendation. I’ve always avoided the plugins as being too much “magic” — so I can control my web app startup / shutdown directly myself.
Makes it easier to switch build tools too 🙂
Okay new qustion, (file-response) causes Opera to download the file (html file) instead of rendering it.. Content-Type being funky?
@sova Possibly. If you're on a unix-y system you can use curl -I
to see what HTTP headers you get back from that request.
That would tell you whether Content-Type is being set or not. I'd have to look at the source (of Ring) to know whether (file-response ...)
sets that header.
OK, @sova no, ring.util.response/file-response
does not set Content-Type so you need to explicitly set that yourself: https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/util/response.clj#L136-L148
(-> (resp/file-response ...) (resp/content-type "text/html"))
or you could use the content-type
middleware (which will automatically set the Content-Type header based on the file extension in the URL, if no Content-Type is already set).
To be honest, I'd recommend using ring-defaults
to set up your middleware so you don't have to worry about this much. That automatically adds the content type middleware and a bunch of other useful stuff...
@seancorfield ah thank you so much. what i'm using already has wrap-defaults and wrap-params but they are not doing the content-type setting, which is interesting...
What is your URI for the request? The content type middleware assumes the URI ends in .something and uses that something to look up a content type.
So your URI would need to end in .htm
or .html
to automatically set Content-Type to "text/html"
.
Oh. Yeah I suppose I'll have to set it manually then. I was just working with
(defroutes
(GET "/" [] (index)))
Yup, if you're serving files that don't match any presumed "extension" in the URI, you'll need to set the content type yourself (I've run into this several times before -- (resp/response "Hello!")
doesn't set "text/html"
or "text/plain"
so some browsers will download that response...
Yeah the download is kinda funny. I dig why it happens but I think every page I want to serve is "text/html"
I guess I can just use the normal ring response map and manually have a :headers field
I tend to have a html
function in my Ring apps like this: (defn html [body] (-> (resp/response body) (resp/content-type "text/html")))
(from memory -- I'm not at my main computer right now)
Ah okay. Things are working. Awesome 🙂
Thanks a lot for your help @seancorfield