fix(core): update

This commit is contained in:
2022-07-29 03:39:05 +02:00
parent 10857aa12b
commit 7284924b26
6 changed files with 135 additions and 29 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/smartproxy',
version: '3.0.6',
version: '3.0.7',
description: 'a proxy for handling high workloads of proxying'
}

View File

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

View File

@ -0,0 +1,32 @@
import * as plugins from './smartproxy.plugins.js';
export class SslRedirect {
httpServer: plugins.http.Server;
port: number;
constructor(portArg: number) {
this.port = portArg;
}
public async start() {
this.httpServer = plugins.http.createServer((request, response) => {
const requestUrl = new URL(request.url, `http://${request.headers.host}`);
const completeUrlWithoutProtocol = `${requestUrl.host}${requestUrl.pathname}${requestUrl.search}`;
const redirectUrl = `https://${completeUrlWithoutProtocol}`;
console.log(`Got http request for http://${completeUrlWithoutProtocol}`);
console.log(`Redirecting to ${redirectUrl}`);
response.writeHead(302, {
Location: redirectUrl,
});
response.end();
});
this.httpServer.listen(this.port);
}
public async stop() {
const done = plugins.smartpromise.defer();
this.httpServer.close(() => {
done.resolve();
});
await done.promise;
}
}

View File

@ -1,9 +1,8 @@
import * as plugins from './smartproxy.plugins.js';
import * as net from 'net';
let netServer: plugins.net.Server;
let httpServer: plugins.http.Server;
export class PortProxy {
netServer: plugins.net.Server;
fromPort: number;
toPort: number;
@ -23,7 +22,7 @@ export class PortProxy {
from.destroy();
to.destroy();
};
netServer = net
this.netServer = net
.createServer((from) => {
const to = net.createConnection({
host: 'localhost',
@ -63,10 +62,8 @@ export class PortProxy {
public async stop() {
const done = plugins.smartpromise.defer();
httpServer.close(() => {
netServer.close(() => {
done.resolve();
});
this.netServer.close(() => {
done.resolve();
});
await done.promise;
}