Background:
I'm trying to create a backend for a 'Single Page App' web client, that routes all requests to the index.html entrypoint except for anything under /assets/
. "/" is mapped to /index.html in a ResourceHandler, and works fine.
Problem: I want to match all paths that do not start with '/assets/' with the RequestMapping in Spring. This works if I positively match 'assets', but not if I negatively match 'assets' in the regex.
@ControllerAdvice
@RequestMapping(value="/**")
public class SPARouter {
@RequestMapping(value = {"/{path:(?!assets)}/**"}, method = RequestMethod.GET)
public String router() {
return "forward:/";
}
}
The above code does not work as it never matches any URL.
If I replace "/{path:(?!assets)}/**"
with "/{path:assets}/**"
it will match a URL like /assets/...
So the thing that does not work is the negative lookahead / match in the regex.
Is it possible to negatively match a pattern in this way?