smartproxy/ts/smartproxy.portproxy.ts

29 lines
616 B
TypeScript
Raw Normal View History

2019-08-22 13:09:48 +00:00
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as net from 'net';
2019-08-22 14:14:50 +00:00
const server = net
.createServer(from => {
const to = net.createConnection({
2019-08-22 13:09:48 +00:00
host: 'localhost',
port: 8001
2019-08-22 14:14:50 +00:00
});
from.pipe(to);
to.pipe(from);
})
.listen(8000);
2019-08-22 13:09:48 +00:00
const portProxyCalls = {
stop: async () => {
const done = plugins.smartpromise.defer();
server.close(() => {
done.resolve();
});
await done.promise;
}
};
export type TPortProxyCalls = typeof portProxyCalls;
expose(portProxyCalls);
2019-08-22 14:14:50 +00:00
console.log('PortProxy Initialized');