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 # gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
variables:
GIT_STRATEGY: clone
cache: cache:
paths: paths:

View File

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

View File

@ -15,7 +15,7 @@ tap.test('should start the testproxy', async () => {
await testProxy.start(); 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); await tools.delayFor(1000);
}); });

View File

@ -47,19 +47,19 @@ export class ProxyWorker {
wscConnected.resolve(); wscConnected.resolve();
}); });
ws.on('message', async (message) => { ws.on('message', async message => {
await wscConnected.promise; await wscConnected.promise;
wsc.emit('message', message); wsc.emit('message', message);
}); });
wsc.on('message', (message) => { wsc.on('message', message => {
ws.emit('message', message); ws.emit('message', message);
}); });
// handle closing // handle closing
ws.on('close', (message) => { ws.on('close', message => {
wsc.close(); wsc.close();
}); });
wsc.on('close', (message) => { wsc.on('close', message => {
ws.close(); ws.close();
}); });
}); });
@ -103,4 +103,4 @@ const proxyWorkerCalls = {
export type TProxyWorkerCalls = typeof proxyWorkerCalls; export type TProxyWorkerCalls = typeof proxyWorkerCalls;
expose(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 proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>; 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 // TODO search for old hostCandidates with that target
this.reverseConfigs = reverseConfigsArg; this.reverseConfigs = reverseConfigsArg;
if (this.proxyWorkerFunctions) { if (this.proxyWorkerFunctions) {
@ -17,17 +19,21 @@ export class SmartProxy {
} }
} }
public async start () { public async start() {
this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker')); this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(
new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker')
);
this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs); 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(); await this.proxyWorkerFunctions.start();
console.log('successfully spawned portproxy and proxyworkers!'); console.log('successfully spawned portproxy and proxyworkers!');
} }
public async stop () { public async stop() {
await this.proxyWorkerFunctions.stop(); await this.proxyWorkerFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions); await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
console.log('proxy worker stopped'); console.log('proxy worker stopped');
@ -36,6 +42,4 @@ export class SmartProxy {
console.log('portproxy stopped'); console.log('portproxy stopped');
console.log('Terminated all childs!'); console.log('Terminated all childs!');
} }
} }

View File

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

View File

@ -1,14 +1,16 @@
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.createServer(from => { const server = net
const to = net.createConnection({ .createServer(from => {
const to = net.createConnection({
host: 'localhost', host: 'localhost',
port: 8001 port: 8001
}); });
from.pipe(to); from.pipe(to);
to.pipe(from); to.pipe(from);
}).listen(8000); })
.listen(8000);
const portProxyCalls = { const portProxyCalls = {
stop: async () => { stop: async () => {
@ -23,4 +25,4 @@ const portProxyCalls = {
export type TPortProxyCalls = typeof portProxyCalls; export type TPortProxyCalls = typeof portProxyCalls;
expose(portProxyCalls); expose(portProxyCalls);
console.log('PortProxy Initialized'); console.log('PortProxy Initialized');