Skip to content

Instantly share code, notes, and snippets.

@tillmannheigel
Last active June 26, 2018 15:33
Show Gist options
  • Select an option

  • Save tillmannheigel/abdef1bd03908689e10bcb22c94059c6 to your computer and use it in GitHub Desktop.

Select an option

Save tillmannheigel/abdef1bd03908689e10bcb22c94059c6 to your computer and use it in GitHub Desktop.

Revisions

  1. Tillmann Heigel revised this gist Jun 26, 2018. No changes.
  2. Tillmann Heigel renamed this gist Jun 26, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Tillmann Heigel revised this gist Jun 26, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,6 @@ public class Application {
    }

    public static void main(String[] args) {
    SpringApplication.run(FrocRouterApplication.class, args);
    SpringApplication.run(Application.class, args);
    }
    }
  4. Tillmann Heigel created this gist Jun 26, 2018.
    38 changes: 38 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    @SpringBootApplication
    public class Application {

    @Bean
    public RouteLocator staticRoutes(RouteLocatorBuilder builder) {
    return builder
    .routes()
    .route(defaultRoute())
    .build();
    }

    private Function<PredicateSpec, Route.Builder> defaultRoute() {
    return r -> r
    .path("/**")
    .filters(defaultFilters())
    .uri("lb://application:8080");
    }

    private Function<GatewayFilterSpec, UriSpec> defaultFilters() {
    return f -> f
    .preserveHostHeader()
    .filter(this::addCustomHeader)
    .addResponseHeader("x-static-router-header", random() + "");
    }

    private Mono<Void> addCustomHeader(ServerWebExchange exchange, GatewayFilterChain chain) {
    exchange.getResponse().getHeaders().add("x-dynamic-router-header", random() + "");
    return chain.filter(exchange);
    }

    private double random(){
    return Math.random();
    }

    public static void main(String[] args) {
    SpringApplication.run(FrocRouterApplication.class, args);
    }
    }