I'm currently migrating a spring-boot app to spring-boot 2 and webflux. Everything looks great and webflux is an amazing integration of Project Reactor into the spring ecosystem. So first thanks for the great work!
Our app serves a SPA which takes use of the History-API, which means there are urls they can only be accessed via a client side router and do not have a corresponding resource in the serving app. That means it should return the index for every resource which cannot be found on the server because the client side router takes care of that. Before Webflux I implemented this with customizing the WebMvcConfigurer like this:
I did not make the PathResourceLookupFunction public, for two reasons:
All other non-utility classes in the package are package protected, so exposing this class would make it the odd one out.
Keeping the class non-public allows us to change it without breaking extending classes.
Instead, we now expose the resource router function in RouterFunctions.resourceLookupFunction(String, Resource), returning a Function<ServerRequest, Mono<Resource>> that can be composed upon. This allows for a functional solution to the problem, rather than one based on inheritance.
@poutsma I've run into exactly the same issue as Michael Gmeiner here before and adopted your solution for my application. Delivery of the defaultResource (and all other resources from my React-generated build directory) works just fine.
However, with this configuration all requests are mapped to this RouterFunction, even the ones for e.g. /actuator/mappings/ or my /api/graphql/ endpoint (created by ). Is there a way I can make route configurations coexist, e.g. by configuring a precedence over routes?