1
votes

I would like to setup zuul and the underlying microservices in a way that all services will be under the '/gateway' context.

For example:

Microservice 1 has : http://localhost:8081/api/hello

Microservice 2 has : http://localhost:8082/api/bye

I would want to be able to access the microservices via zuul as follows:

Microservice 1 : http://localhost:8080/gateway/microservice1/api/hello

Microservice 2: http://localhost:8080/gateway/microservice2/api/bye

I have tried to set this up, although it seems the requests are not getting routed correctly.

The reason I would like the front end to route all client side REST calls to server that begin with '/gateway' is that it provides simpler maintenance to the front end.

My application.yml:

zuul:
 prefix: /gateway
   routes:
     microservice1:
        path: /microservice1/**
        serviceId: microservice1
        strip-prefix: true
     microservice2:
        path: /microservice2/**
        serviceId: microservice2
        strip-prefix: true

Thank you

1
how do you have the two microservice and the gateway under same port number... are they deployed on different server or everything is packaged all together. - Grinish Nepal
Each service is launched on its own port. Updated the question. Zuul is on 8080, M1 is on 8081 and M2 is on 8082. Updated the question. Thank you - Rami Del Toro

1 Answers

2
votes

Try this config and let me know if this works out for you. I think you will have to define a global strip-prefix:true like below. Actually it should also work without strip prefix since by default it will strip both the prefix.

zuul:
 prefix: /gateway
 strip-prefix: true
   routes:
     microservice1:
        path: /microservice1/**
        serviceId: microservice1
        strip-prefix: true
     microservice2:
        path: /microservice2/**
        serviceId: microservice2
        strip-prefix: true