Fork me on GitHub
#pedestal
<
2022-04-26
>
tomekw08:04:03

Is it possible to match /foo, /foo/, and /foo/:bar with one route def with optional :bar? :thinking_face:

Linus Ericsson09:04:27

no, i really don't think so.

😞 1
😭 1
quan xing15:04:22

I defined routes :

(defn login
  [request]
  (log/info request))

(def routes #{["/design_unit/register" :get register :route-name :resgister]
              ["/design_unit/saveleader" 
               :get (conj inter/common-interceptors `save-leader)]
              
              ["/login" :post [inter/common-interceptors `login]]
              })
but run error:
Syntax error (AssertionError) compiling at (app\server.clj:6:1).
Assert failed: In row 9, the vector of handlers should have been a bunch of interceptors but was [[#Interceptor{:name :io.pedestal.http.body-params/body-params} #Interceptor{:name :io.pedestal.http/html-body}] app.design-unit.bzarea.handler/login].
The whole route was: ["/login" :post [[#Interceptor{:name :io.pedestal.http.body-params/body-params} #Interceptor{:name :io.pedestal.http/html-body}] app.design-unit.bzarea.handler/login] :route-name :login]
(every? (fn* [p1__11405#] (satisfies? interceptor/IntoInterceptor p1__11405#)) handlers)
I'm referring to this URL http://pedestal.io/reference/routing-quick-reference use conj is ok ,but use [] is reoprt error.

Braden Shepherdson16:04:59

that spot in the route is supposed to be either a function (`register`) or a list of interceptors. (conj inter/common-interceptors 'save-leader) returns a list, with save-leader at the end.

Braden Shepherdson16:04:34

but if the common-interceptors is [a b c], the broken /login route's list looks like this [[a b c] 'login], which isn't right.