1

I need the following:

Any request to

and so on, should be forwarded to

https://localhost:8443/a/web/index.html

Now, this is how I managed to do that:

@Controller
public class ForwardController {
    @RequestMapping(value = "/*", method = RequestMethod.GET)
    public String redirectRoot(HttpServletRequest request) {
        return "forward:/a/web/index.html";
    }
}

The problem is:

This also matches https://localhost:8443/api/ (note the / at the end).

This is a problem because that's where I want the Spring Data REST base path to be:

spring.data.rest.base-path=/api/

/api != /api/ when it comes to REST endpoints.

What should work but somehow doesn't

I have tried several different regular expressions but I am still not able to accomplish what I want. For example (demo):

@RequestMapping(value = "/[^/]+", method = RequestMethod.GET)

Will now work for Spring Data - I'm getting all the resource information I expect, but accessing https://localhost:8443/ is now broken and the web-client cannot be reached anymore.

The same goes for

@RequestMapping(value = "/{path}", method = RequestMethod.GET)
@RequestMapping(value = "/{path:[^/]+}", method = RequestMethod.GET)

which behave like /* (also matches the next /).

This issue is already haunting me for weeks and still no solution insight.


This whole question can also be seen as:

Why is "/[^/]+" not matching https://localhost:8443/whatever ?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • have you seen this? https://stackoverflow.com/questions/36594644/spring-controller-to-handle-all-requests-not-matched-by-other-controllers – Nestor Sokil Mar 30 '19 at 10:46
  • @NestorSokil Hm, I don't think this answer can help me here. Just adding an endpoint which matches everything unmatched does not help here - it is actually the problem. – Stefan Falk Mar 30 '19 at 11:13
  • https://stackoverflow.com/questions/12043618/how-do-i-map-spring-mvc-controller-to-a-uri-with-and-without-trailing-slash/45258671#45258671 – sparse Mar 30 '19 at 15:08

1 Answers1

0

Regex are usually not the fastest thing to try. You can send a list of paths to

 @RequestMApping(value={"", "/", "/test", "/api"},  method = RequestMethod.GET)

See Multiple Spring @RequestMapping annotations