fix(core): update
This commit is contained in:
@ -3,12 +3,22 @@ import * as plugins from './smartproxy.plugins';
|
||||
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
|
||||
import { TPortProxyCalls } from './smartproxy.portproxy';
|
||||
|
||||
export interface ISmartProxyOptions {
|
||||
port?: number;
|
||||
}
|
||||
|
||||
export class SmartProxy {
|
||||
public smartsystem = new plugins.smartsystem.Smartsystem();
|
||||
public reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
|
||||
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
|
||||
|
||||
public options: ISmartProxyOptions;
|
||||
|
||||
constructor(optionsArg: ISmartProxyOptions = {}) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
public async updateReversConfigs(
|
||||
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
|
||||
) {
|
||||
@ -28,6 +38,8 @@ export class SmartProxy {
|
||||
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
|
||||
new plugins.smartspawn.Worker('./smartproxy.portproxy')
|
||||
);
|
||||
|
||||
await this.portProxyFunctions.start(this.options.port);
|
||||
await this.proxyWorkerFunctions.start();
|
||||
|
||||
console.log('successfully spawned portproxy and proxyworkers!');
|
||||
|
@ -1,21 +1,24 @@
|
||||
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({
|
||||
host: 'localhost',
|
||||
port: 8001
|
||||
});
|
||||
from.pipe(to);
|
||||
to.pipe(from);
|
||||
})
|
||||
.listen(8000);
|
||||
let netServer: plugins.net.Server;
|
||||
|
||||
const portProxyCalls = {
|
||||
start: async (portArg = 8000) => {
|
||||
netServer = net
|
||||
.createServer(from => {
|
||||
const to = net.createConnection({
|
||||
host: 'localhost',
|
||||
port: 8001
|
||||
});
|
||||
from.pipe(to);
|
||||
to.pipe(from);
|
||||
})
|
||||
.listen(portArg);
|
||||
},
|
||||
stop: async () => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
server.close(() => {
|
||||
netServer.close(() => {
|
||||
done.resolve();
|
||||
});
|
||||
await done.promise;
|
||||
|
Reference in New Issue
Block a user