2013-02-24 55 views
0

以下組合路線有效。組合路線時發生錯誤

(defroutes app-routes 
    (GET "/" [] (index)) 
    (GET "/twauth" [] (tw/authorize)) 
    (ANY "/twcallback" [] (do 
          (tw/callback) 
          (index))) 
    (route/resources "/") 
    (route/not-found "Not Found")) 

(def app (handler/site app-routes)) 

但是,我得到以下錯誤。它拋出一個java.nullpointer.exception。我在這裏做錯了什麼?

(defroutes應用的路由 (GET 「/」[](索引)) (GET 「/ twauth」[](TW /授權)) (ANY 「/ twcallback」[](做 (TW /回調) (指數))))

(defroutes base-routes 
    (route/resources "/") 
    (route/not-found "Not Found")) 

(def app 
    (-> app-routes 
     base-routes 
     handler/site)) 

回答

1

你的基本路線的所有要求相匹配。我認爲有以下說明它更好:

(defroutes base-routes 
    (route/not-found "Not found")) 

(def app 
    (-> app-routes 
     base-routes 
     handler/site)) 

不管你的應用程序的路由做什麼上面,基本路線是經過檢查,總是會返回未找到。請注意,每個請求都通過兩個路由進行線程化,而不是首先匹配wins。

所以你需要可以移動的基路由到您的應用程序,如航線後備 - 像你已經在你的工作例子一樣 - 或者應用程序撰寫他們:

(def app 
    (-> (routes app-routes base-routes) 
     handler/site)) 

這裏由路線確保第一場比賽獲勝。