reitit

weavejester 2025-06-08T13:21:30.352449Z

I'm having an issue where routes aren't being matched when they're nested. Does Reitit have any debugging options that might help track down where the issue is?

juhoteperi 2025-06-09T07:30:29.149739Z

@weavejester Yes this is by design. Right now, Reitit only considers the leaf nodes on the route tree for endpoints. There is no logic which can choose if a non-leaf node should be considered a endpoint or not. (I think there is some logic for match-by-name for choose endpoints based on if the route-data has :name or such.) (I think we did consider adding a option which could do this, so user could check for :name or :handler or whatever they use.)

weavejester 2025-06-08T14:05:01.797679Z

To clarify the issue, when I check the routes manually everything works, but when I add coercion and middleware, nested routes aren't processed. There's clearly something going wrong somewhere, but it's all very opaque. Ideally I'd like Reitit to report back on why the router hasn't matched a route.

weavejester 2025-06-08T14:29:08.468119Z

I think I've tracked down the issue by going through the configuration and middleware piece by piece. It's no fault of Reitit's, but the lack of transparency once the router was built made it hard to figure out the exact component that was going wrong. I'm unsure of the best way to address this, however.

valerauko 2025-06-08T15:50:48.071059Z

What was the problem?

weavejester 2025-06-08T15:52:19.689469Z

Some code altered the routes in an unexpected way, so the routes I was looking at weren't the routes passed into the router.

weavejester 2025-06-08T15:54:09.242689Z

So when I tested the routes by passing them directly to the router in the REPL they worked, but when the server started they didn't. It was very confusing until I realised the issue.

valerauko 2025-06-08T15:55:51.304629Z

Depending on what you're doing of course, but if you have :name on your routes, then you can match-by-name and check what the final result (with all the :data and :middleware and whatnot) looks like Even without :name you should be able to match-by-path to see if the issue is in the router or somewhere outside of it I don't know if there is a function to list all routes in a router

ikitommi 2025-06-08T19:06:30.399809Z

Calling reitit.core/routes on router returns the flattened route tree. I can be useful in debugging.

weavejester 2025-06-08T19:53:55.021659Z

That's super helpful, because I don't seem to have fixed the issue, and I've added some debugging right before the router is constructed so I know the routes are all correct. Hopefully I can figure out just what's going wrong if I poke it enough.

weavejester 2025-06-08T20:03:37.587619Z

Ahh, I see. I've misunderstood the syntax. I had assumed that:

["/foo" {:name :foo} ["/bar" {:name :bar}]]
Was equivalent to:
["/foo" ["" {:name :foo}] ["/bar" {:name :bar}]]
But it seems like a route with nested routes cannot itself be an endpoint. Is that deliberate? It seems odd.

weavejester 2025-06-08T20:05:00.230019Z

(Incidentally, that tip about reitit.core/routes saved me a lot of time)