Fork me on GitHub
#reitit
<
2018-10-24
>
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.

ikitommi11:10:50

@hannu.hartikainen currently, nothing built-in. But there’s a issue for it: https://github.com/metosin/reitit/issues/92

ikitommi11:10:02

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

ikitommi11:10:20

.. 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 🙂

ikitommi11:10:03

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

ikitommi11:10:20

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

ikitommi11:10:46

(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.

ikitommi11:10:27

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

ikitommi11:10:54

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

https://github.com/julienschmidt/httprouter > 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.

ikitommi11:10:42

bit more github stars btw 🙂

shaolang15:10:28

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?

ikitommi16:10:32

@shaolang welcome! there is guide how to set middleware to certain routes only: https://cljdoc.org/d/metosin/reitit/0.2.4/doc/ring/ring-router#middleware

ikitommi16:10:36

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.

shaun-mahood20:10:22

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?