Compojure路线问题

Man*_*tis 4 routes clojure compojure

我有一个小的compojure站点,其路由定义如下:

(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"))
Run Code Online (Sandbox Code Playgroud)

当我尝试加载项目时,我收到此错误:
java.lang.Exception: Unsupported binding form: (or (serve-file (params :*)) :next)

我究竟做错了什么?我从互联网上分散的例子中获取了大部分内容.

添加空向量后,我收到此错误:
java.lang.Exception: Unable to resolve symbol: serve-file in this context

Mic*_*zyk 6

我想你错过了一个约束形式:

(GET "/*" {params :params} (or (serve-file (params :*)) :next))
        ; ^- note the binding form
Run Code Online (Sandbox Code Playgroud)

  • 在最近的Compojure中,我认为它应该是`{params:params}`而不是空向量,因为Compojure不再为你设置魔法`params`. (2认同)