fix(core): update
This commit is contained in:
parent
c7b8b6ff66
commit
3f935b3a03
@ -4,7 +4,7 @@ import * as smartproxy from '../ts/index';
|
|||||||
let testProxy: smartproxy.SmartProxy;
|
let testProxy: smartproxy.SmartProxy;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testProxy = new smartproxy.SmartProxy();
|
testProxy = new smartproxy.SmartProxy({});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start the testproxy', async () => {
|
tap.test('should start the testproxy', async () => {
|
||||||
@ -15,7 +15,7 @@ tap.test('should supply reverse proxy config', async () => {
|
|||||||
testProxy.updateReversConfigs([{
|
testProxy.updateReversConfigs([{
|
||||||
destinationIp: 'localhost',
|
destinationIp: 'localhost',
|
||||||
destinationPort: '3000',
|
destinationPort: '3000',
|
||||||
hostName: 'central.eu',
|
hostName: 'push.rocks',
|
||||||
privateKey: `-----BEGIN PRIVATE KEY-----
|
privateKey: `-----BEGIN PRIVATE KEY-----
|
||||||
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
|
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
|
||||||
3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+
|
3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+
|
||||||
@ -101,7 +101,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should wait for 60 seconds', async tools => {
|
tap.test('should wait for 60 seconds', async tools => {
|
||||||
await tools.delayFor(60000);
|
await tools.delayFor(10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should close the testproxy', async () => {
|
tap.test('should close the testproxy', async () => {
|
||||||
|
@ -3,12 +3,22 @@ import * as plugins from './smartproxy.plugins';
|
|||||||
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
|
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
|
||||||
import { TPortProxyCalls } from './smartproxy.portproxy';
|
import { TPortProxyCalls } from './smartproxy.portproxy';
|
||||||
|
|
||||||
|
export interface ISmartProxyOptions {
|
||||||
|
port?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class SmartProxy {
|
export class SmartProxy {
|
||||||
public smartsystem = new plugins.smartsystem.Smartsystem();
|
public smartsystem = new plugins.smartsystem.Smartsystem();
|
||||||
public reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
public reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||||
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
|
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
|
||||||
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
|
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
|
||||||
|
|
||||||
|
public options: ISmartProxyOptions;
|
||||||
|
|
||||||
|
constructor(optionsArg: ISmartProxyOptions = {}) {
|
||||||
|
this.options = optionsArg;
|
||||||
|
}
|
||||||
|
|
||||||
public async updateReversConfigs(
|
public async updateReversConfigs(
|
||||||
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
|
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
|
||||||
) {
|
) {
|
||||||
@ -28,6 +38,8 @@ export class SmartProxy {
|
|||||||
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
|
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
|
||||||
new plugins.smartspawn.Worker('./smartproxy.portproxy')
|
new plugins.smartspawn.Worker('./smartproxy.portproxy')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.portProxyFunctions.start(this.options.port);
|
||||||
await this.proxyWorkerFunctions.start();
|
await this.proxyWorkerFunctions.start();
|
||||||
|
|
||||||
console.log('successfully spawned portproxy and proxyworkers!');
|
console.log('successfully spawned portproxy and proxyworkers!');
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
import * as plugins from './smartproxy.plugins';
|
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';
|
||||||
const server = net
|
let netServer: plugins.net.Server;
|
||||||
|
|
||||||
|
const portProxyCalls = {
|
||||||
|
start: async (portArg = 8000) => {
|
||||||
|
netServer = net
|
||||||
.createServer(from => {
|
.createServer(from => {
|
||||||
const to = net.createConnection({
|
const to = net.createConnection({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
@ -10,12 +14,11 @@ const server = net
|
|||||||
from.pipe(to);
|
from.pipe(to);
|
||||||
to.pipe(from);
|
to.pipe(from);
|
||||||
})
|
})
|
||||||
.listen(8000);
|
.listen(portArg);
|
||||||
|
},
|
||||||
const portProxyCalls = {
|
|
||||||
stop: async () => {
|
stop: async () => {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
server.close(() => {
|
netServer.close(() => {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
|
Loading…
Reference in New Issue
Block a user