I am creating a toy Pedestal service intended to have the following resources:
/
/movies
/movies/today
/movies/:iso-date
where :iso-date
matches ####-##-##The constraint for the last route is defined with the following snippet:
^:constraints {:iso-date #"\d{4}-\d{2}-\d{2}"}
Whenever the route containing this constraint is present in the route table I am unable to GET its sibling route /movies/today
; instead I am getting a "Not Found" response instead. When the constraint-having route is removed, however, a GET of /movies/today
succeeds.
The Pedestal routes I have defined using terse format look like so:
(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}]]]]])
Have I constructed this route table correctly in order to achieve the routing behaviour that I want?
NB: Printing the compiled routes gives me the result that I would expect in that all of the routes are present the generated :path-re
regexes match as expected at the 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})
I solved this problem in pedestal version 0.4.1-SNAPSHOT.
(io.pedestal.http.route/router my-routes :linear-search)
Use :linear-search
, instead of :prefix-tree
.