express-gateway
Version:
A microservices API gateway built on top of ExpressJS
21 lines (16 loc) • 469 B
JavaScript
const url = require('url');
module.exports = class RoundRobin {
constructor (proxyOptions, endpoints) {
this.proxyOptions = proxyOptions;
this.endpoints = endpoints;
this.endpointIndex = 0;
this.endpointMaxIndex = this.endpoints.length - 1;
}
nextTarget () {
const target = this.endpoints[this.endpointIndex++];
if (this.endpointIndex > this.endpointMaxIndex) {
this.endpointIndex = 0;
}
return url.parse(target);
}
};