default-filters
Örnek
Şöyle yaparız. Böylece authentication token servislere de geçilir.
spring:cloud:gateway:default-filters:- TokenRelay
Örnek
Şöyle yaparız
spring:main:web-application-type: reactiveprofiles:active: devcloud:gateway:default-filters:- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Originglobalcors:corsConfigurations:'[/**]':allowedOrigins: "*"allowedMethods: "*"allowedHeaders: "*"httpclient:pool:max-idle-time: 10sssl:useInsecureTrustManager: truefilter:StripPrefix: 1remove-non-proxy-headers:headers:- Keep-Alive- TE- Trailer- Transfer-Encoding- Upgrade- Connection- Hostroutes:- id: wsuri: ws://192.168.0.125:5554predicates:- Path=/websocket/**- id: request_size_routeuri: http://192.168.0.125:5554predicates:- Path=/**
StripPrefix
Baştaki ön eklerden kaç tanesinin silineceğini belirtir. Örneğin istek
"product-service.yourplatform.com/product-service/products" adresine gelseydi ve biz
"product-service/products" adresine yönlendirmek isteseydik, StripPrefix=1 yapardıkÖrnek
/products adresi için Şöyle yaparız.
spring: cloud: gateway: routes: - id: products uri: https://dummyjson.com/products predicates: - Path=/products filters: - StripPrefix=0
aynı şeyi bu sefer "products/java" adresi için kodla şöyle yaparız
@SpringBootApplication public class GatewayApplication { public static void main(String[] args) { SpringApplication.run(GatewayApplication.class, args); } @Bean public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() .route(p -> p.path("/products-java") .filters(f -> f.setPath("/products")) .uri("https://dummyjson.com")) .build(); } }
Şu iki adres te aynı yere yönlendirilir
ahttp://localhost:9000/products http://localhost:9000/products-java
Hiç yorum yok:
Yorum Gönder