Here is my code that has a function spilling out simple sytle sheets:
(defroutes app-routes (GET "/style.css" [] (my-css-function)))
(defn my-css-function [] "(css strings...)")
And when I enter "/style.css" in my browser, it spills out plain text strings that can not be used by html file, while being sytanxically correct. I guess compojure is messing with the context type so that the browser is interpreting my string as something strange rather than being a normal css file?
The my-css-function
returns a string, which compojure returns as the content for the response, if no content-type is explicitly specified then my guess is that either text/plain
or text/html
are used.
If you want to specify the text/css
content type for the response, you could do it in the following way:
(defn my-css-function []
{:headers {"Content-Type" "text/css"}
:body "body { background-color: #CCC; }"})