如何配置兄弟 Pedestal 路由,以便在使用 :constraints 时可以访问所有路由?

How does one configure sibling Pedestal routes so that all are accessible when using :constraints?

我正在创建一个玩具基座服务,旨在拥有以下资源:

最后一条路线的约束是使用以下代码段定义的:

^:constraints {:iso-date #"\d{4}-\d{2}-\d{2}"}

只要包含此约束的路由出现在路由 table 中,我就无法获取其兄弟路由 /movies/today;相反,我得到的是 "Not Found" 响应。然而,当删除具有约束的路由时,/movies/today 的 GET 成功。

我使用简洁格式定义的基座路线如下所示:

(defroutes routes
  [[["/" {:get root-page}
     ["/movies" ^:interceptors [fetch-movies]
      {:get movies-page}
      ["/today" {:get movies-for-today-page}]
      ["/:iso-date" ^:constraints {:iso-date #"\d{4}-\d{2}-\d{2}"}
       {:get movies-for-date-page}]]]]])

为了实现我想要的路由行为,我是否正确构建了这条路由table?

注意:打印编译后的路由给出了我期望的结果,因为所有路由都存在,生成的 :path-re 正则表达式与 REPL 中预期的匹配:

({:path-parts [""],
  :path-params [],
  :interceptors
  [{:name :foobar.service/root-page,
    :enter
    #object[io.pedestal.interceptor.helpers$before$fn__7359 0x14501070 "io.pedestal.interceptor.helpers$before$fn__7359@14501070"],
    :leave nil,
    :error nil}],
  :path "/",
  :method :get,
  :path-re #"/\Q\E",
  :route-name :foobar.service/root-page}
 {:path-parts ["" "movies"],
  :path-params [],
  :interceptors
  [{:name :foobar.service/fetch-movies,
    :enter
    #object[io.pedestal.interceptor.helpers$on_request$fn__7401 0x2aa85cc4 "io.pedestal.interceptor.helpers$on_request$fn__7401@2aa85cc4"],
    :leave nil,
    :error nil}
   {:name :foobar.service/movies-page,
    :enter
    #object[io.pedestal.interceptor.helpers$before$fn__7359 0x30ffc3c0 "io.pedestal.interceptor.helpers$before$fn__7359@30ffc3c0"],
    :leave nil,
    :error nil}],
  :path "/movies",
  :method :get,
  :path-re #"/\Qmovies\E",
  :route-name :foobar.service/movies-page}
 {:path-parts ["" "movies" "today"],
  :path-params [],
  :interceptors
  [{:name :foobar.service/fetch-movies,
    :enter
    #object[io.pedestal.interceptor.helpers$on_request$fn__7401 0x2aa85cc4 "io.pedestal.interceptor.helpers$on_request$fn__7401@2aa85cc4"],
    :leave nil,
    :error nil}
   {:name :foobar.service/movies-for-today-page,
    :enter
    #object[io.pedestal.interceptor.helpers$before$fn__7359 0x3726fc3b "io.pedestal.interceptor.helpers$before$fn__7359@3726fc3b"],
    :leave nil,
    :error nil}],
  :path "/movies/today",
  :method :get,
  :path-re #"/\Qmovies\E/\Qtoday\E",
  :route-name :foobar.service/movies-for-today-page}
 {:path-parts ["" "movies" :iso-date],
  :path-params [:iso-date],
  :interceptors
  [{:name :foobar.service/fetch-movies,
    :enter
    #object[io.pedestal.interceptor.helpers$on_request$fn__7401 0x2aa85cc4 "io.pedestal.interceptor.helpers$on_request$fn__7401@2aa85cc4"],
    :leave nil,
    :error nil}
   {:name :foobar.service/movies-for-date-page,
    :enter
    #object[io.pedestal.interceptor.helpers$before$fn__7359 0x93fb20b "io.pedestal.interceptor.helpers$before$fn__7359@93fb20b"],
    :leave nil,
    :error nil}],
  :path "/movies/:iso-date",
  :path-constraints {:iso-date "(\d{4}-\d{2}-\d{2})"},
  :query-constraints {},
  :method :get,
  :path-re #"/\Qmovies\E/(\d{4}-\d{2}-\d{2})",
  :route-name :foobar.service/movies-for-date-page})

我在 pedestal 版本 0.4.1-SNAPSHOT 中解决了这个问题。

(io.pedestal.http.route/router my-routes :linear-search)

使用:linear-search,而不是:prefix-tree