iirc what you're after is what many web frameworks call "middleware", which is not something that Jester has. However, there's a fork from a couple of years ago which adds it. It was covered in NimConf 2020 and it seemed really cool to me.
I think it would be nice if this functionality made it into upstream Jester!
You don't need middleware for this.
You can create a route that runs before all requests (or all requests under a specific sub-path), for example: https://github.com/dom96/jester/blob/master/tests/alltest.nim#L49.
So the following should work for you:
before re"/*?":
if rateLimited(request): halt Http502, "Rate Limited"