From 736113eb4ef0b577af8ae13693a10218c9053a16 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 23 Feb 2020 19:03:25 +0000 Subject: [PATCH] fix(core): update --- test/test.ts | 2 +- ts/smartproxy.portproxy.ts | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/test/test.ts b/test/test.ts index 923b464..6427de3 100644 --- a/test/test.ts +++ b/test/test.ts @@ -12,7 +12,7 @@ tap.test('should start the testproxy', async () => { }); tap.test('should supply reverse proxy config', async () => { - testProxy.updateReversConfigs([ + testProxy.updateReverseConfigs([ { destinationIp: 'localhost', destinationPort: '3000', diff --git a/ts/smartproxy.portproxy.ts b/ts/smartproxy.portproxy.ts index c0e60be..0a56a12 100644 --- a/ts/smartproxy.portproxy.ts +++ b/ts/smartproxy.portproxy.ts @@ -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; }