smartproxy/ts/smartproxy.classes.router.ts

21 lines
759 B
TypeScript
Raw Normal View History

2019-08-20 16:42:52 +00:00
import * as plugins from './smartproxy.plugins';
2019-08-20 17:02:13 +00:00
export class SmartproxyRouter {
2019-08-22 10:49:29 +00:00
public reverseCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
2019-08-20 17:02:13 +00:00
2019-08-22 10:49:29 +00:00
/**
* sets a new set of reverse configs to be routed to
* @param reverseCandidatesArg
*/
public setNewCandidates(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.reverseCandidates = reverseCandidatesArg;
}
public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig {
const originalHost = req.headers.host;
const correspodingReverseProxyConfig = this.reverseCandidates.find(reverseConfig => {
return reverseConfig.hostName === originalHost;
});
return correspodingReverseProxyConfig;
2019-08-20 17:02:13 +00:00
}
}