clojurecompojureenlive

Compojure Not Serving CSS When I Use Multiple Parameters


I'm trying to mimic Wordpress permalink using Compojure, but why all the static files (css, js, and img) are not found when I use multiple parameter? Here is my code.

(defroutes approutes
  (GET "/" [] (posts-for-home))
  (GET "/:year/:month/:title" [year month title :as {uri :uri}] (single/tpl-single uri))
  (route/resources "/")
  (route/not-found "<h1>Page not found</h1>"))

(def app
  (handler/site approutes))

I saw in browser debug console the css was served from http://localhost:3000/2014/11/test/css/main.css instead of http://localhost:3000/css/main.css. Then I added one test route and only used a parameter like this:

(GET "/:testparameter" [testparameter] (single/tpl-single testparameter))

and that route was working perfectly. When I visited http://localhost:3000/justfortest, all the static files were served from the root path. What should I do to solve this multiple parameters issue? Thanks in advance for the answer.


Solution

  • Finally I solved this issue after replacing <link rel="stylesheet" href="css/main.css"> to <link rel="stylesheet" href="/css/main.css">. What a trivial problem and I didn't notice it for a day. Lol so embarrasing.