Fork me on GitHub
#reitit
<
2018-11-11
>
ikitommi19:11:37

^:-- inspecting interceptor steps via deep-diff transformer function (`:enter`, :leave and :error).

ikitommi20:11:44

[metosin/reitit "0.2.7"] out, fixes bug with aliased spec coercion.

ikitommi20:11:33

to get the diffs: • [metosin/reitit "0.2.8-SNAPSHOT"] • with middleware, add a router option :reitit.middleware/transform reitit.ring.middleware.dev/print-request-diffs • with interceptors, add a router option :reitit.interceptor/transform reitit.http.interceptors.dev/print-context-diffs

ikitommi20:11:17

@shaun-mahood if you have ideas & time, improvements most welcome for the diffs.

shaun-mahood21:11:31

@ikitommi Looks great, I should get a chance to play with it this week!

phil21:11:28

Hey. I'm trying to implement a the following route:

[["/v1"
      ["/" {:get {:handler (fn [req] {:body {:hello ["from /v1"]}})}}]]
     ["/*" {:get {:handler (fn [req] {:body {:hello ["from anything else"]}})}}]]

phil21:11:20

Where /* is effectively a catch-all for anything that isn't under

/v1
, but I'm failing.

phil21:11:36

If it's clear what I'm trying to do, any tips?

ikitommi21:11:23

@phil you have a route conflict:

CompilerException clojure.lang.ExceptionInfo: Router contains conflicting route paths:

   /v1/
-> /*

ikitommi21:11:09

you can resolve that by disabling the conflict resolution, see https://metosin.github.io/reitit/basics/route_conflicts.html

phil21:11:39

Hey, @ikitommi I tried that, and also switching to a linear router.

phil21:11:48

Perhaps I need to implement default-handler?

ikitommi21:11:52

(def r
  (r/router
    [["/v1"
      ["/" {:get {:handler (fn [req] {:body {:hello ["from /v1"]}})}}]]
     ["/*" {:get {:handler (fn [req] {:body {:hello ["from anything else"]}})}}]]
    {:conflicts nil}))

(r/match-by-path r "/kikka")
;#reitit.core.Match{:template "/*",
;                   :data {:get {:handler #object[reitit.http.interceptors.dev$fn__27957
;                                                 0x6814e716
;                                                 "[email protected]"]}},
;                   :result nil,
;                   :path-params {: "kikka"},
;                   :path "/kikka"}

ikitommi21:11:08

I think it works ok?

ikitommi21:11:26

but, the default-handler is usually better for “catch everything else”.

ikitommi21:11:23

also, for conflicing routes, reitit always fallbacks automatically to linear-router

ikitommi21:11:54

(r/router-name r)
; :linear-router

ikitommi21:11:52

but if you want to match to /v1, replace the "/" with "". the path strings get concatenated, ping @phil

phil21:11:30

Thanks, @ikitommi - giving it a try now.

ikitommi21:11:50

(map first (r/routes r))
; ("/v1/" "/*")

phil21:11:13

I was putting :conflicts in the :data map, not the top-level.

phil21:11:20

Thanks again for your help.

ikitommi06:11:30

your welcome