Forwardings Requests to static content in Spring Boot Webflux

The following WebFilter redirects incoming requests for / to a static HTML file, index.html. ToIndexPageRedirection.java package com.hascode.tutorial; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; @Component public class ToIndexPageRedirection implements WebFilter { @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getURI().getPath().equals("/")) { return chain.filter( exchange.mutate().request( exchange.getRequest().mutate().path("/index.html").build() ).build() ); } return chain.filter(exchange); } } Ressources: JavaDocs WebFilter

August 16, 2022 · 1 min · 59 words · Micha Kops