Compare commits

...

6 Commits

Author SHA1 Message Date
29549b126e 2.0.1 2020-02-23 19:03:26 +00:00
736113eb4e fix(core): update 2020-02-23 19:03:25 +00:00
3b2d140836 2.0.0 2020-02-07 19:36:13 +00:00
70690f6400 BREAKING CHANGE(API): updateReversConfigs -> updateReverseConfigs 2020-02-07 19:36:12 +00:00
ae561e3e88 1.0.38 2020-02-07 16:06:12 +00:00
8a02a0c506 fix(core): update 2020-02-07 16:06:11 +00:00
6 changed files with 364 additions and 592 deletions

930
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "1.0.37", "version": "2.0.1",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -12,7 +12,7 @@ tap.test('should start the testproxy', async () => {
}); });
tap.test('should supply reverse proxy config', async () => { tap.test('should supply reverse proxy config', async () => {
testProxy.updateReversConfigs([ testProxy.updateReverseConfigs([
{ {
destinationIp: 'localhost', destinationIp: 'localhost',
destinationPort: '3000', destinationPort: '3000',

View File

@ -231,7 +231,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.port}`); console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.port}`);
} }
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.IReverseProxyConfig[]) { public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.proxyConfigs = proxyConfigsArg; this.proxyConfigs = proxyConfigsArg;
this.router.setNewProxyConfigs(proxyConfigsArg); this.router.setNewProxyConfigs(proxyConfigsArg);
for (const hostCandidate of this.proxyConfigs) { for (const hostCandidate of this.proxyConfigs) {

View File

@ -19,7 +19,7 @@ export class SmartProxy {
this.options = optionsArg; this.options = optionsArg;
} }
public async updateReversConfigs( public async updateReverseConfigs(
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[] reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
) { ) {
// TODO search for old hostCandidates with that target // TODO search for old hostCandidates with that target

View File

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