fix(core): update

This commit is contained in:
2020-02-23 19:03:25 +00:00
parent 3b2d140836
commit 736113eb4e
2 changed files with 19 additions and 3 deletions

View File

@ -2,9 +2,23 @@ import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as net from 'net';
let netServer: plugins.net.Server;
let httpServer: plugins.http.Server;
const portProxyCalls = {
start: async (portArg = 8000) => {
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();
});
httpServer.listen(7999);
netServer = net
.createServer(from => {
const to = net.createConnection({
@ -19,8 +33,10 @@ const portProxyCalls = {
},
stop: async () => {
const done = plugins.smartpromise.defer();
netServer.close(() => {
done.resolve();
httpServer.close(() => {
netServer.close(() => {
done.resolve();
});
});
await done.promise;
}