ExpressGateway / express-gateway

A microservices API Gateway built on top of Express.js
https://www.express-gateway.io
Apache License 2.0
2.98k stars 348 forks source link

distinguish the services with same path #964

Closed ramiz4 closed 4 years ago

ramiz4 commented 4 years ago
const express = require('express');
const svc1 = express();
svc1.get('/healthz', (req, res, next) => {
    res.send({ name: 'svc1', status: 'healthy' });
    next();
}).listen(process.env.PORT || 1337);

const svc2 = express();
svc2.get('/healthz', (req, res, next) => {
    res.send({ name: 'svc2', status: 'healthy' });
    next();
}).listen(process.env.PORT2 || 1338);

How can I distinguish the services in the express-gateway if the paths are the same?

http:
  port: 8080
admin:
  port: 9876
  hostname: localhost
apiEndpoints:
  svc1API:
    host: 'localhost'
    paths:
      - '/health-check'
  svc2API:
    host: 'localhost'
    paths:
      - '/health-check'
serviceEndpoints:
  svc1Service:
    url: 'http://localhost:1337'
  svc2Service:
    url: 'http://localhost:1338'
policies:
  - proxy
pipelines:
  - name: svc1
    apiEndpoints:
      - svc1API
    policies:
      - proxy:
        - action:
            serviceEndpoint: svc1Service
  - name: svc2
    apiEndpoints:
      - svc2API
    policies:
      - proxy:
        - action:
            serviceEndpoint: svc2Service
XVincentX commented 4 years ago

I am not so sure I understand your use case here; what are you trying to do? If you put two services under the same path how is Express Gateway supposed to know which service it should use?

With the current configuration, it will go based on the service order.

ramiz4 commented 4 years ago

The express-gateway could differentiate the services by the service name, in which you give the service name to the express-gateway. Like this http://localhost:8080/svc1/health-check http://localhost:8080/svc2/health-check

XVincentX commented 4 years ago

Then put the entire url in the path svc1/healt-check