【问题标题】:Compojure Routes IssuesCompojure 路由问题
【发布时间】:2011-04-23 01:01:02
【问题描述】:

我有一个小型复合站点,其路由定义如下:

(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"))

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

我做错了什么?我从互联网上的零散示例中获取了大部分内容。

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

【问题讨论】:

    标签: clojure routes compojure


    【解决方案1】:

    我认为您缺少绑定表单:

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

    【讨论】:

    • 在最近的 Compojure 中,我认为应该是 {params :params} 而不是空向量,因为 Compojure 不再为您设置魔术 params 本地。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2021-07-19
    • 2012-10-11
    • 2013-04-20
    • 2013-12-21
    • 2011-08-14
    • 2012-05-31
    相关资源
    最近更新 更多