Java - Spring Boot 2.0 WebFlux configuration for static resources
1
2
3
4
5
6
7
8
9
10
11
@Value("classpath:/static/index.html")
private Resource indexHtml;
@Bean
RouterFunction<?> routerFunction() {
RouterFunction router = RouterFunctions.resources("/**", new ClassPathResource("static/"))
// workaround solution for forwarding / to /index.html
.andRoute(GET("/"), request -> {
return ServerResponse.ok().contentType(TEXT_HTML).syncBody(indexHtml);
});
return router;
}