Grails: Use regex with filter

204 Views Asked by At

I have two URL's addresses which I have filter for everyone of them:

all(uri: '/api/first/**')
{
    before =
}
all(uri: '/api/second/**')
{
    before =
}

I want to write just one filter for both. So I have tried to write a filter with regex:

all(uri: '\\/api\\/(first|second)\\/.*', regex: true)
{
    before =
}

But it doesn't work. I have tried many ways ('**' / '.*' / invert: true) But didn't succeed.

Does someone know where the mistake and what the right way to write the filter?

Thanks...

1

There are 1 best solutions below

3
Wiktor Stribiżew On

As per the documentation, uri is an ant path and does not support regular expressions. You need to rely on find:

all(regex: true, find: '/api/(first|second)/.*')
{
   before = {
       ...
   }
}