smartproxy/ts/smartproxy.portproxy.ts
2020-02-07 13:04:11 +00:00

33 lines
806 B
TypeScript

import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as net from 'net';
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);
console.log(`PortProxy -> OK: Now listening on port ${portArg}`);
},
stop: async () => {
const done = plugins.smartpromise.defer();
netServer.close(() => {
done.resolve();
});
await done.promise;
}
};
export type TPortProxyCalls = typeof portProxyCalls;
expose(portProxyCalls);
console.log('PortProxy Initialized');