Skip to content

Instantly share code, notes, and snippets.

@fitzoh
Last active February 10, 2018 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitzoh/7f4c4acc2a8145dc958e4c06560f0fe1 to your computer and use it in GitHub Desktop.
Save fitzoh/7f4c4acc2a8145dc958e4c06560f0fe1 to your computer and use it in GitHub Desktop.
simple-gateway-route-service
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, SimpleLoggingFilter loggingFilter) {
return builder.routes()
.route(r ->
r.header(FORWARDED_URL, ".*")
.and()
.header(PROXY_METADATA, ".*")
.and()
.header(PROXY_SIGNATURE, ".*")
.filters(f -> f.add(loggingFilter))
.uri("http://google.com:80"))
.build();
}
@Component
public class SimpleLoggingFilter implements GatewayFilter {
private static final Logger log = LoggerFactory.getLogger(SimpleLoggingFilter.class);
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
log.info("Method:{} Host:{} Path:{} QueryParams:{}",
exchange.getRequest().getMethod(),
exchange.getRequest().getURI().getHost(),
exchange.getRequest().getURI().getPath(),
exchange.getRequest().getQueryParams());
return chain.filter(exchange);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment