Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created August 21, 2019 17:17
Show Gist options
  • Save timjonesdev/82aa9f0a654bc33a6836dcd3738e46af to your computer and use it in GitHub Desktop.
Save timjonesdev/82aa9f0a654bc33a6836dcd3738e46af to your computer and use it in GitHub Desktop.
A static web filter
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 StaticWebFilter 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment