PrefixPath フィルター

PrefixPath フィルターは 1 つの prefix パラメーターを取ります。次の例では、PrefixPath フィルターを構成します。

application.yml
spring:
  cloud:
    gateway:
      mvc:
        routes:
        - id: prefixpath_route
          uri: https://example.org
          filters:
          - PrefixPath=/mypath
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.prefixPath;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;

@Configuration
class RouteConfiguration {

    @Bean
    public RouterFunction<ServerResponse> gatewayRouterFunctionsPrefixPath() {
		return route("prefixpath_route")
				.GET("/**", http("https://example.org"))
					.before("/mypath")
					.build();
    }
}

これにより、一致するすべてのリクエストのパスに /mypath のプレフィックスが付けられます。/hello へのリクエストは /mypath/hello に送信されます。