weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.08k stars 259 forks source link

Static resource routing not working #211

Closed wbehrens-on-gh closed 2 years ago

wbehrens-on-gh commented 2 years ago
(def public (.getPath (io/resource "www/")))
(def srv-opts {:port 8080})

(http/defroutes app
  (http/GET "/" [] {:body (views/index)})
  (route/resources public)
  (route/not-found "<h1>Page not found</h1>"))

(defn -main []
  (println "Starting server on port:" (srv-opts :port))
  (println "Public dir:" public)
  (httpkit/run-server app srv-opts)
  (clj/repl))

I have the directory resources/www, when I try and link to css/styles.css it's not found. When looking in the dev console there is nothing being served for static resources.

wbehrens-on-gh commented 2 years ago

update: still no solution to this

weavejester commented 2 years ago

You're passing a directory path to route/resources, not the route path. Instead, use:

(route/resources "/" {:root "www"})