Created
April 12, 2023 19:01
-
-
Save AdrianoJS/beb3623c553494d7157731f158ec7ed9 to your computer and use it in GitHub Desktop.
spring-cloud-gateway-example-stage-2-routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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