2
votes

Iam using Spring Boot + Cloud | Zuul Proxy(org.springframework.cloud:spring-cloud-starter-zuul:1.0.0.RELEASE). I have below configuration.


info:
  component: Zuul Server
endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false
zuul:
  ignoredServices: "*"
  proxy:
     mapping: /api/v1
     addProxyHeaders: true
  routes:
    service:
       path: /service/**
       serviceId: service
       stripPrefix: false
server:
  port: 8765
logging:
  level:
    ROOT: INFO
    org.springframework.web: INFO
eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/


I want the access URL to service as http://localhost:8765/api/v1/service as done in the above configuration(ref: https://github.com/joshlong/microservices-lab/blob/master/api-gateway/gateway/src/main/resources/application.yml).

But this is not working, the URL http://localhost:8765/service works.

Is there a way to achieve this, since i dont want the individual services to have the /api/v1 context.

1

1 Answers

4
votes

Not sure where you got the zuul.proxy.* options. They aren't valid. zuul.addProxyHeaders is valid.

What you want is zuul.prefix=/api/v1. The default is to strip that prefix when forwarding. So /api/v1/service forwards to /service.