fix(core): update

This commit is contained in:
Philipp Kunz 2021-02-03 19:42:27 +00:00
parent 963ad6efa4
commit b64523b0b2

View File

@ -10,6 +10,10 @@ export class ProxyWorker {
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>(); public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
public defaultHeaders: { [key: string]: string } = {}; public defaultHeaders: { [key: string]: string } = {};
public alreadyAddedReverseConfigs: {
[hostName: string]: plugins.tsclass.network.IReverseProxyConfig;
} = {};
/** /**
* starts the proxyInstance * starts the proxyInstance
*/ */
@ -162,7 +166,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
{ {
method: req.method, method: req.method,
headers: req.headers, headers: req.headers,
keepAlive: true keepAlive: true,
}, },
true, // lets make this streaming true, // lets make this streaming
(request) => { (request) => {
@ -215,11 +219,20 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
}); });
// handle closing // handle closing
ws.on('close', (message) => { const cleanUp = () => {
ws.removeAllListeners();
ws.close();
ws.terminate();
wsc.removeAllListeners();
wsc.close(); wsc.close();
wsc.terminate();
};
ws.on('close', (message) => {
cleanUp();
}); });
wsc.on('close', (message) => { wsc.on('close', (message) => {
ws.close(); cleanUp();
}); });
}); });
this.httpsServer.keepAliveTimeout = 61000; this.httpsServer.keepAliveTimeout = 61000;
@ -228,22 +241,22 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
this.httpsServer.on('connection', (connection: plugins.net.Socket) => { this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
connection.setTimeout(120000); connection.setTimeout(120000);
this.socketMap.add(connection); this.socketMap.add(connection);
const cleanupConnection = (connectionArg: plugins.net.Socket) => { const cleanupConnection = () => {
connectionArg.removeAllListeners();
this.socketMap.remove(connection); this.socketMap.remove(connection);
connection.removeAllListeners();
connection.destroy(); connection.destroy();
} };
connection.on('close', () => { connection.on('close', () => {
cleanupConnection(connection); cleanupConnection();
}); });
connection.on('error', () => { connection.on('error', () => {
cleanupConnection(connection); cleanupConnection();
}); });
connection.on('end', () => { connection.on('end', () => {
cleanupConnection(connection); cleanupConnection();
}); });
connection.on('timeout', () => { connection.on('timeout', () => {
cleanupConnection(connection); cleanupConnection();
}); });
}); });
@ -256,10 +269,27 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
this.router.setNewProxyConfigs(proxyConfigsArg); this.router.setNewProxyConfigs(proxyConfigsArg);
for (const hostCandidate of this.proxyConfigs) { for (const hostCandidate of this.proxyConfigs) {
// console.log(hostCandidate); // console.log(hostCandidate);
const existingHostNameConfig = this.alreadyAddedReverseConfigs[hostCandidate.hostName];
if (!existingHostNameConfig) {
this.alreadyAddedReverseConfigs[hostCandidate.hostName] = hostCandidate;
} else {
if (
existingHostNameConfig.publicKey === hostCandidate.publicKey &&
existingHostNameConfig.privateKey === hostCandidate.privateKey
) {
continue;
} else {
this.alreadyAddedReverseConfigs[hostCandidate.hostName] = hostCandidate;
}
}
this.httpsServer.addContext(hostCandidate.hostName, { this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey, cert: hostCandidate.publicKey,
key: hostCandidate.privateKey, key: hostCandidate.privateKey,
}); });
this.httpsServer;
} }
/* this.httpsServer.close(); /* this.httpsServer.close();
this.httpsServer.listen(this.port); */ this.httpsServer.listen(this.port); */
@ -293,9 +323,9 @@ const proxyWorkerCalls = {
addDefaultHeaders: async (headersArg: { [key: string]: string }) => { addDefaultHeaders: async (headersArg: { [key: string]: string }) => {
proxyWorkerInstance.defaultHeaders = { proxyWorkerInstance.defaultHeaders = {
...proxyWorkerInstance.defaultHeaders, ...proxyWorkerInstance.defaultHeaders,
...headersArg ...headersArg,
}; };
} },
}; };
export type TProxyWorkerCalls = typeof proxyWorkerCalls; export type TProxyWorkerCalls = typeof proxyWorkerCalls;