Fork me on GitHub
Hannu Hartikainen11:10:57

Is there an easy way to match a path both with and without a trailing slash (e.g. /products and /products/)? It would be nice in frontend, as users tend to edit urls manually time to time.


@hannu.hartikainen currently, nothing built-in. But there’s a issue for it:


for today, you could write a helper that does two lookups.

Hannu Hartikainen11:10:15

ok, I might see what implementing it would take if I ever have a bit of free time


.. or strip the trailing from request path and ensure that routes don’t have those.

Hannu Hartikainen11:10:53

yeah, I was thinking that I could just have a middleware that strips trailing slashes or something

Hannu Hartikainen11:10:33

but can there be middleware without ring 🙂


haha. for frontend, you have a code that calls the routing somewhere…


but a helper that takes a router and strips all the trailing spaces would be easy to do.


(r/strip-trailing-spaces router) ; router => router

Hannu Hartikainen11:10:50

yeah. I’m starting to remember now that I delve deeper into my own code.


I think this is resolved elegantly with many other routing libs (but not in Clojure when I checked)…


It’s bit like the ignore-case string lookup: create an index with all lower-cases and lower-case the query too.

ikitommi11:10:48 > Stop caring about trailing slashes: Choose the URL style you like, the router automatically redirects the client if a trailing slash is missing or if there is one extra. Of course it only does so, if the new path has a handler. If you don’t like it, you can turn off this behavior.


bit more github stars btw 🙂


hihi, noob question probably: how do I wrap-anti-forgery to certain routes properly? I've tried middleware/registry, but that didn't work. Or should I just wrap-anti-forgery (and wrap-session) on the entire reitit-created handler?


@shaolang welcome! there is guide how to set middleware to certain routes only:


if your mw doesn’t take parameters, you can just say :middleware [wrap-anti-forgery] to any of the route data. valid scopes are: router, partial path, path/endpoint, method.


I'm moving some code over from a Compojure site and I'm having trouble downloading a generated file from a function that takes a while to return. I'm running into an issue where the reitit version is firing off my function, then returning a blank file instead of waiting for it to return. Is there anything reitit-specific that I should be looking at to figure this out?