I have created a project using lein and then inside the root of the project I created a directory public to place static content.
However, static content is not served as expected.
Here is defroutes:
(defroutes greeter
(GET "/greeter/working" []
(html
[:html
[:head [:tile "bla"]]
[:body [:image "oops.jpg"]]
]
)
)
(GET "/greeter/sayhi" [] "say hi")
(GET "/greeter/" [] "top level")
(route/files "/" {:root (str (System/getProperty "user.dir") "\\public")})
(defn -main []
(run-jetty greeter {:port 3000 :join? false}))
Make sure you know where "user.dir" is actually located. It's not your home directory, it's the working directory of your application, typically where you ran lein ring server
.
I created a new Compojure project with the following handler.clj file to debug this and verify where to place public/
:
(ns static-files.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]))
(def root (str (System/getProperty "user.dir") "/public"))
(defroutes app-routes
(GET "/" [] "Hello World")
(route/files "/" (do (println root) {:root root}))
(route/resources "/")
(route/not-found "Not Found"))
(def app
(handler/site app-routes))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With