fix(core): update

This commit is contained in:
2023-07-27 16:27:50 +02:00
parent 0adb32e7e9
commit 6cdb23ed66
13 changed files with 1691 additions and 1072 deletions

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartproxy',
version: '3.0.58',
name: '@push.rocks/smartproxy',
version: '3.0.59',
description: 'a proxy for handling high workloads of proxying'
}

View File

@ -1,3 +1,3 @@
export * from './smartproxy.classes.networkproxy.js';
export * from './smartproxy.portproxy.js';
export * from './smartproxy.classes.sslredirect.js'
export * from './smartproxy.classes.sslredirect.js';

View File

@ -129,16 +129,20 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
originResponse.writeHead(statusArg, messageArg);
originResponse.end(messageArg);
if (originRequest.socket !== originResponse.socket) {
console.log('hey, something is strange.')
console.log('hey, something is strange.');
}
originResponse.destroy();
};
console.log(`got request: ${originRequest.headers.host}${plugins.url.parse(originRequest.url).path}`);
console.log(
`got request: ${originRequest.headers.host}${plugins.url.parse(originRequest.url).path}`
);
const destinationConfig = this.router.routeReq(originRequest);
if (!destinationConfig) {
console.log(`${originRequest.headers.host} can't be routed properly. Terminating request.`);
console.log(
`${originRequest.headers.host} can't be routed properly. Terminating request.`
);
endOriginReqRes();
return;
}
@ -189,7 +193,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
headers: {
...originRequest.headers,
'X-Forwarded-Host': originRequest.headers.host,
'X-Forwarded-Proto': 'https'
'X-Forwarded-Proto': 'https',
},
keepAlive: true,
},
@ -213,7 +217,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
});
proxyRequest.on('error', () => {
endOriginReqRes();
})
});
}
);
originResponse.statusCode = proxyResponse.statusCode;
@ -238,58 +242,65 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
});
proxyResponse.on('timeout', () => {
originResponse.end();
originResponse.destroy()
originResponse.destroy();
});
}
);
// Enable websockets
const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer });
wsServer.on('connection', async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
console.log(`wss proxy: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
let wsOutgoing: plugins.wsDefault;
const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer });
wsServer.on(
'connection',
async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
console.log(
`wss proxy: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`
);
const outGoingDeferred = plugins.smartpromise.defer();
let wsOutgoing: plugins.wsDefault;
try {
wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
console.log('wss proxy: initiated outgoing proxy');
wsOutgoing.on('open', async () => {
outGoingDeferred.resolve();
})
} catch (err) {
console.log(err);
wsIncoming.terminate();
return;
const outGoingDeferred = plugins.smartpromise.defer();
try {
wsOutgoing = new plugins.wsDefault(
`ws://${this.router.routeReq(reqArg).destinationIp}:${
this.router.routeReq(reqArg).destinationPort
}${reqArg.url}`
);
console.log('wss proxy: initiated outgoing proxy');
wsOutgoing.on('open', async () => {
outGoingDeferred.resolve();
});
} catch (err) {
console.log(err);
wsIncoming.terminate();
return;
}
wsIncoming.on('message', async (message, isBinary) => {
await outGoingDeferred.promise;
// console.log("client to upstream", message);
wsOutgoing.send(message, { binary: isBinary });
});
wsOutgoing.on('message', async (message, isBinary) => {
// console.log("upstream to client", message);
wsIncoming.send(message, { binary: isBinary });
});
const terminateWsOutgoing = () => {
wsOutgoing.terminate();
console.log('terminated outgoing ws.');
};
wsIncoming.on('error', () => terminateWsOutgoing());
wsIncoming.on('close', () => terminateWsOutgoing());
const terminateWsIncoming = () => {
wsIncoming.terminate();
console.log('terminated incoming ws.');
};
wsOutgoing.on('error', () => terminateWsIncoming());
wsOutgoing.on('close', () => terminateWsIncoming());
}
wsIncoming.on("message", async (message, isBinary) => {
await outGoingDeferred.promise;
// console.log("client to upstream", message);
wsOutgoing.send(message, { binary: isBinary });
});
wsOutgoing.on("message", async (message, isBinary) => {
// console.log("upstream to client", message);
wsIncoming.send(message, { binary: isBinary });
});
const terminateWsOutgoing = () => {
wsOutgoing.terminate();
console.log('terminated outgoing ws.');
}
wsIncoming.on("error", () => terminateWsOutgoing());
wsIncoming.on("close", () => terminateWsOutgoing());
const terminateWsIncoming = () => {
wsIncoming.terminate();
console.log('terminated incoming ws.');
}
wsOutgoing.on("error", () => terminateWsIncoming());
wsOutgoing.on("close", () => terminateWsIncoming());
});
);
this.httpsServer.keepAliveTimeout = 600 * 1000;
this.httpsServer.headersTimeout = 600 * 1000;
@ -314,7 +325,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
});
connection.on('timeout', () => {
cleanupConnection();
})
});
});
this.httpsServer.listen(this.options.port);

View File

@ -29,4 +29,4 @@ export class SslRedirect {
});
await done.promise;
}
}
}

View File

@ -12,11 +12,11 @@ import * as tsclass from '@tsclass/tsclass';
export { tsclass };
// pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartstring from '@pushrocks/smartstring';
import * as lik from '@push.rocks/lik';
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrequest from '@push.rocks/smartrequest';
import * as smartstring from '@push.rocks/smartstring';
export { lik, smartdelay, smartrequest, smartpromise, smartstring };