I need to handle some GET requests in order to forward to multiple Angular clients.
https://example.com/web/index.html // Client 1
https://example.com/admin/index.html // Client 2
Since I don't want to use fragmented (#
-ed) paths for /web
things get rather annyoing.
This is my current not working solution:
@Controller
public class ForwardController {
@RequestMapping(value = "/*", method = RequestMethod.GET)
public String redirectRoot(HttpServletRequest request) {
String req = request.getRequestURI();
if (req.startsWith("/admin/")) {
return this.redirectAdminTool(request);
}
return "forward:/web/index.html";
}
@RequestMapping(value = "/web/{path:[^.]*}", method = RequestMethod.GET)
public String redirectWeb(HttpServletRequest request) {
return "forward:/web/index.html";
}
@RequestMapping(value = "/admin/{path:[^.]*}", method = RequestMethod.GET)
public String redirectAdminTool(HttpServletRequest request) {
return "forward:/admin/index.html";
}
}
With this, what does work is accessing e.g.
/web/pricing
but what does not work is accessing
/web/pricing/vienna
I can access /web/pricing
via browser, hit "refresh" and everything will work. But it does not for /web/pricing/vienna
.
Now, I cannot figure out how to handle the requests and how to forward them in order to make sub-paths like /web/pricing/vienna
to work as well.
Is there any way I can make this work?
If I change the @RequestMapping
path to something like /web/**
the whole thing ends up in an endless loop and breaks the server.
What I probably need is an expression like this:
/web(/[^\\.]*)
which would result in
MATCH: /web/pricing
MATCH: /web/specials/city
MATCH: /web/specials/city/street
NO MATCH: /web/index.html
However, Spring does not like this regex: /web(/[^\\.]*)
In the end this issue boils down to finding a way to match everythign except static resources below /web
.