Skip to content

Instantly share code, notes, and snippets.

@xinyii
Last active April 21, 2021 06:25
Show Gist options
  • Save xinyii/0c4d6f6d8776b75ac1431841475b851d to your computer and use it in GitHub Desktop.
Save xinyii/0c4d6f6d8776b75ac1431841475b851d to your computer and use it in GitHub Desktop.
[Spring Cloud Gateway] #spring
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("path_route", r -> r.method(HttpMethod.GET).and().path("/mock/**")
.filters(f -> f.rewritePath("/mock/(?<segment>.*)", "/${segment}"))
.uri("https://6000221fcb21e10017af883f.mockapi.io/api/v1"))
.build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment