Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getProxyService(name: string, method: string): { service: T, node: IServer } {
const lb: ILoadbalance = NestCloud.global.loadbalance;
if (!lb) {
return { service: null, node: null };
}
const node = lb.choose(this.config.service);
const methodKey = `${node.id}/${method}`;
if (!this.serviceCache.get(methodKey)) {
if (!this.proxyCache.has(node.id)) {
const proxy = new ClientGrpcProxy({
url: `${node.address}:${node.port}`,
package: this.config.package,
protoPath: this.config.protoPath,
});
this.proxyCache.set(node.id, proxy);
}
const proxy = this.proxyCache.get(node.id);
const service = proxy.getService(name);
this.serviceCache.set(methodKey, service);
}
const service = this.serviceCache.get(methodKey) as T;
return { service, node };
}
}
constructor(config: IClientConfig) {
this.config = config;
this.proxy = new ClientGrpcProxy(config);
}