Application I'm working serving static files of a frontend application inside the spring cloud gateway. At the moment any route other than the predefined once are ended up being 404 as expected.
@Bean
public RouterFunction<ServerResponse> htmlRemoteAppointmentRouter(
@Value("classpath:/static/index.html")
Resource html) {
return route(GET("/"), request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(html))
.andRoute(GET("/home/{*path}"), request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(html))
.andRoute(GET("/user/{*path}"), request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(html));
}
How ever, what I'm expecting is to handle the 404 error and serve the index.html for all the failing GET requests.
I tried to add the /error mapping. However on client, it still shows the Whitelabel Error Page for 404.
@Controller
public class ErrorHandler implements ErrorController {
@RequestMapping("/error")
public String something() {
return "error";
}
}