Reputation: 302
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?
Upvotes: 2
Views: 261
Reputation: 10691
You need to modify your code to include the following:
(route/resources "/") ; special route for serving static files like css
; default root directory is resources/public/
You may check this answer for more detail.
Upvotes: 0
Reputation: 9920
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; }"})
Upvotes: 4