Skip to content

Instantly share code, notes, and snippets.

@AdrianoJS
Created April 12, 2023 19:01
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 AdrianoJS/beb3623c553494d7157731f158ec7ed9 to your computer and use it in GitHub Desktop.
Save AdrianoJS/beb3623c553494d7157731f158ec7ed9 to your computer and use it in GitHub Desktop.
spring-cloud-gateway-example-stage-2-routes
package no.embriq.api.gateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
@Component
public class Routes implements RouteLocator {
@Autowired
private RouteLocatorBuilder builder;
@Value("${app.dependencies.foo.baseUrl}")
private String fooUrl;
@Value("${app.dependencies.bar.baseUrl}")
private String barUrl;
@Override
public Flux<Route> getRoutes() {
return builder.routes()
.route("optional id",
r -> r.path("/api/add")
.uri(fooUrl))
.route(r -> r.path("/bar/ping")
.filters(f -> f.rewritePath("/bar/ping", "/api/ping"))
.uri(barUrl))
.build().getRoutes();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment