Reputation: 1472
I have 2 services and I want to create an API gateway for these services.
Service 1
endpoints:
/
/jungle
Service 2
endpoints:
/
/jungle
Expected Behavior:
API Gateway handle a request as :
apigateway.com/leon =======>> Leon service '/'
apigateway.com/leon/jungle =======>> Leon service '/jungle'
apigateway.com/tiger =======>> Tiger service '/'
apigateway.com/tiger/jungle =======>> Tiger service '/jungle'
So I want to match the first path of the incoming request URL with services.
And my gateway. config.yaml file like that:
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
leon:
host: localhost
methods : [ 'POST', 'GET' ]
paths: '/*'
tiger:
host: localhost
methods : ['POST', 'GET']
paths: '/*'
serviceEndpoints:
leonsrv:
url: 'http://leon-service.us-west-2.compute.amazonaws.com/'
tigersrv:
url: 'http://tiger-service.us-west-2.compute.amazonaws.com/'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
- name: leon
apiEndpoints:
- leon
policies:
- proxy:
- action:
serviceEndpoint: leonsrv
changeOrigin: true
- name: tiger
apiEndpoints:
- tiger
policies:
- proxy:
- action:
serviceEndpoint: tigersrv
changeOrigin: true
But Its not working. I cannot send a request to tiger service.
How Can solve this problem please help!
Upvotes: 0
Views: 803
Reputation: 2406
The two endpoints defined in your apiEndpoints section are the same: http://localhost/*. You need to include more of your target URLs to get allow express-gateway to distinguish between them:
apiEndpoints:
leon:
host: localhost
methods : [ 'POST', 'GET' ]
paths: [ '/leon/', '/leon/*' ]
tiger:
host: localhost
methods : ['POST', 'GET']
paths: [ '/tiger/', '/tiger/*' ]
Upvotes: 0