views:

98

answers:

1

I have a small compojure site, with the routes defined as such:

(defroutes example
  (GET "/" [] {:status 200
               :headers {"Content-Type" "text/html"}
               :body (home)})
  (GET "/*" (or (serve-file (params :*)) :next))
  (GET "/execute/" [] {:status 200
                      :headers {"Content-Type" "text/html"}
                      :body (execute-changes)})
  (GET "/status/" [] {:status 200
                    :headers {"Content-Type" "text/html"}
                    :body (status)})
  (route/not-found "Page not found"))

When I try to load the project, I get this error:
java.lang.Exception: Unsupported binding form: (or (serve-file (params :*)) :next)

What am I doing wrong? I took most of this from scattered examples on the internet.

After adding the empty vector, I get this error:
java.lang.Exception: Unable to resolve symbol: serve-file in this context

+1  A: 

I think you're missing a binding form:

(GET "/*" {params :params} (or (serve-file (params :*)) :next))
        ; ^- note the binding form
Michał Marczyk
In recent Compojure I think it should be `{params :params}` instead of an empty vector, because Compojure doesn't set up the magic `params` local for you any longer.
Brian Carper
@Brian Carper: Oh, that's right. Fixed. Thanks!
Michał Marczyk