fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-22 16:14:50 +02:00
parent 4113bf551e
commit 2883d2b926
7 changed files with 35 additions and 36 deletions

View File

@ -1,5 +1,7 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
variables:
GIT_STRATEGY: clone
cache:
paths:

View File

@ -9,7 +9,7 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)",
"build": "(tsbuild --web)",
"format": "(gitzone format)"
},
"devDependencies": {
@ -41,4 +41,4 @@
"npmextra.json",
"readme.md"
]
}
}

View File

@ -15,7 +15,7 @@ tap.test('should start the testproxy', async () => {
await testProxy.start();
});
tap.test('should wait for 5 seconds', async (tools) => {
tap.test('should wait for 5 seconds', async tools => {
await tools.delayFor(1000);
});

View File

@ -47,19 +47,19 @@ export class ProxyWorker {
wscConnected.resolve();
});
ws.on('message', async (message) => {
ws.on('message', async message => {
await wscConnected.promise;
wsc.emit('message', message);
});
wsc.on('message', (message) => {
wsc.on('message', message => {
ws.emit('message', message);
});
// handle closing
ws.on('close', (message) => {
ws.on('close', message => {
wsc.close();
});
wsc.on('close', (message) => {
wsc.on('close', message => {
ws.close();
});
});
@ -103,4 +103,4 @@ const proxyWorkerCalls = {
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
expose(proxyWorkerCalls);
console.log('ProxyWorker initialized');
console.log('ProxyWorker initialized');

View File

@ -9,7 +9,9 @@ export class SmartProxy {
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
public async updateReversConfigs(reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
public async updateReversConfigs(
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
) {
// TODO search for old hostCandidates with that target
this.reverseConfigs = reverseConfigsArg;
if (this.proxyWorkerFunctions) {
@ -17,17 +19,21 @@ export class SmartProxy {
}
}
public async start () {
this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker'));
public async start() {
this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(
new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker')
);
this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(new plugins.smartspawn.Worker('./smartproxy.portproxy'));
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
new plugins.smartspawn.Worker('./smartproxy.portproxy')
);
await this.proxyWorkerFunctions.start();
console.log('successfully spawned portproxy and proxyworkers!');
}
public async stop () {
public async stop() {
await this.proxyWorkerFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
console.log('proxy worker stopped');
@ -36,6 +42,4 @@ export class SmartProxy {
console.log('portproxy stopped');
console.log('Terminated all childs!');
}
}

View File

@ -7,9 +7,7 @@ export { http, https };
// tsclass scope
import * as tsclass from '@tsclass/tsclass';
export {
tsclass
};
export { tsclass };
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
@ -17,16 +15,9 @@ import * as smartrequest from '@pushrocks/smartrequest';
import * as smartspawn from '@pushrocks/smartspawn';
import * as smartsystem from '@pushrocks/smartsystem';
export {
smartrequest,
smartpromise,
smartspawn,
smartsystem,
};
export { smartrequest, smartpromise, smartspawn, smartsystem };
// third party scope
import * as ws from 'ws';
export {
ws
};
export { ws };

View File

@ -1,14 +1,16 @@
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as net from 'net';
const server = net.createServer(from => {
const to = net.createConnection({
const server = net
.createServer(from => {
const to = net.createConnection({
host: 'localhost',
port: 8001
});
from.pipe(to);
to.pipe(from);
}).listen(8000);
});
from.pipe(to);
to.pipe(from);
})
.listen(8000);
const portProxyCalls = {
stop: async () => {
@ -23,4 +25,4 @@ const portProxyCalls = {
export type TPortProxyCalls = typeof portProxyCalls;
expose(portProxyCalls);
console.log('PortProxy Initialized');
console.log('PortProxy Initialized');