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 app-routes (GET "/" [] (index)) (GET "/twauth" [] (tw/authorize)) (ANY "/twcallback" [] (do (tw/callback) (index))) )

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

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

1 に答える 1

1

ベースルートはすべてのリクエストに一致します。次の例がそれをよりよく示していると思います。

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

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

上記の app-routes で何をしても、base-routes は後でチェックされ、常に not-found が返されます。各リクエストは、最初の一致が勝つのではなく、両方のルートを介してスレッド化されることに注意してください。

したがって、ベースルートをフォールバックとしてアプリルートに移動する必要があります-実際の例で既に行ったように-またはアプリでそれらを構成します:

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

ここでは、構成されたルートにより、最初のマッチが勝つことが保証されます。

于 2013-04-06T13:26:56.610 に答える