localhost:8080/get
→ http://httpbin.org:80/get
으로 요청 라우팅.route(p -> p.path("/get") .filters(f -> f.addRequestHeader("Hello", "World")) .uri("http://httpbin.org:80"))
localhost:8080/api/v1/get
→ http://httpbin.org:80/get
으로 요청 라우팅.route(p -> p.path("/api/v1/get") .filters(f -> f.setPath("/get")) .uri("http://httpbin.org:80"))
localhost:8080/api/httpbin/get
→ http://httpbin.org:80/get
route("httpbin", p -> p.path("/api/httpbin/**") .filters(f -> f.stripPrefix(2)) .uri("http://httpbin.org:80)) // '/api' - 1, '/httpbin' - 2 해서 2 path 건너뛰기
localhost:8080/api/httpbin/get/123
→ http://httpbin.org:80/get/123
, 단 /get/abc
는 거부됨route("httpbin", p -> p.path("/api/httpbin/get/{num:[0-9]+}") .filters(f -> f.stripPrefix(2)) .uri("http://httpbin.org:80))
route("userById", t -> t.path("/users/**") .filters(rw -> rw.rewritePath("/users/(?<segment>.*)", "/users/${segment}")) .uri("http://localhost:8080/users/"))
implementation 'org.springframework.boot:spring-boot-starter-actuator
' 의존성 추가
management.endpoint.gateway.enabled=true # default value management.endpoints.web.exposure.include=gateway