Compare commits

...

26 Commits

Author SHA1 Message Date
3b2d140836 2.0.0 2020-02-07 19:36:13 +00:00
70690f6400 BREAKING CHANGE(API): updateReversConfigs -> updateReverseConfigs 2020-02-07 19:36:12 +00:00
ae561e3e88 1.0.38 2020-02-07 16:06:12 +00:00
8a02a0c506 fix(core): update 2020-02-07 16:06:11 +00:00
58ec01526a 1.0.37 2020-02-07 13:04:12 +00:00
1c3619040c fix(core): update 2020-02-07 13:04:11 +00:00
0eabdcde28 1.0.36 2020-02-07 12:43:38 +00:00
3f935b3a03 fix(core): update 2020-02-07 12:43:37 +00:00
c7b8b6ff66 1.0.35 2019-11-03 03:06:56 +01:00
a9815c61d2 fix(core): update 2019-11-03 03:06:56 +01:00
82730877ce 1.0.34 2019-11-03 03:05:49 +01:00
b68b143a3f fix(core): update 2019-11-03 03:05:49 +01:00
3e7416574d 1.0.33 2019-11-03 03:04:23 +01:00
7f843bef50 fix(core): update 2019-11-03 03:04:23 +01:00
360c31c6b6 1.0.32 2019-09-29 17:18:41 +02:00
4ca748ec93 fix(core): update 2019-09-29 17:18:40 +02:00
6dd3e473c6 1.0.31 2019-09-29 01:06:07 +02:00
3856a1d7fb fix(core): update 2019-09-29 01:06:07 +02:00
fb76ecfd8a 1.0.30 2019-09-24 16:27:34 +02:00
6c84406574 fix(core): update 2019-09-24 16:27:34 +02:00
945065279f 1.0.29 2019-09-24 16:21:58 +02:00
07a8d9bec6 fix(websockets): now proxying websockets as well 2019-09-24 16:21:57 +02:00
2c55a6b819 1.0.28 2019-09-23 19:20:54 +02:00
8f4421fbc3 fix(core): update 2019-09-23 19:20:53 +02:00
5eebc434bb 1.0.27 2019-09-20 19:19:33 +02:00
ed03c3ec4b fix(core): update 2019-09-20 19:19:33 +02:00
12 changed files with 1080 additions and 830 deletions

View File

@ -1,12 +1,10 @@
# 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:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
@ -22,17 +20,19 @@ mirror:
script: script:
- npmci git mirror - npmci git mirror
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
snyk: snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
@ -49,6 +49,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv - priv
@ -56,22 +57,24 @@ testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
@ -83,9 +86,11 @@ codequality:
allow_failure: true allow_failure: true
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless
- docker - docker
- priv - priv
@ -96,20 +101,20 @@ trigger:
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata stage: metadata
script: script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

View File

@ -1,5 +1,6 @@
{ {
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",

1509
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "1.0.26", "version": "2.0.0",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js", "main": "dist/index.js",
@ -14,29 +14,31 @@
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.7.5", "@types/node": "^13.7.0",
"tslint": "^5.20.0", "tslint": "^6.0.0",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartnetwork": "^1.1.14", "@pushrocks/lik": "^3.0.16",
"@pushrocks/smartpromise": "^3.0.5", "@pushrocks/smartnetwork": "^1.1.18",
"@pushrocks/smartrequest": "^1.1.27", "@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47",
"@pushrocks/smartspawn": "^2.0.9", "@pushrocks/smartspawn": "^2.0.9",
"@pushrocks/smartstring": "^3.0.18",
"@pushrocks/smartsystem": "^2.0.9", "@pushrocks/smartsystem": "^2.0.9",
"@tsclass/tsclass": "^2.0.6", "@tsclass/tsclass": "^3.0.3",
"@types/ws": "^6.0.3", "@types/ws": "^7.2.1",
"ws": "^7.1.2" "ws": "^7.2.1"
}, },
"files": [ "files": [
"ts/*", "ts/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_web/**/*",
"dist_ts_web/*", "dist_ts_web/**/*",
"assets/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"

View File

@ -8,7 +8,7 @@ a proxy for handling high workloads of proxying
* [docs (typedoc)](https://pushrocks.gitlab.io/smartproxy/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartproxy/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartproxy/badges/master/build.svg)](https://gitlab.com/pushrocks/smartproxy/commits/master) [![pipeline status](https://gitlab.com/pushrocks/smartproxy/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/smartproxy/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartproxy/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartproxy/commits/master) [![coverage report](https://gitlab.com/pushrocks/smartproxy/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartproxy/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartproxy.svg)](https://www.npmjs.com/package/@pushrocks/smartproxy) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartproxy.svg)](https://www.npmjs.com/package/@pushrocks/smartproxy)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartproxy/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartproxy) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartproxy/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartproxy)
@ -18,6 +18,11 @@ a proxy for handling high workloads of proxying
## Usage ## Usage
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)

View File

@ -4,7 +4,7 @@ import * as smartproxy from '../ts/index';
let testProxy: smartproxy.SmartProxy; let testProxy: smartproxy.SmartProxy;
tap.test('first test', async () => { tap.test('first test', async () => {
testProxy = new smartproxy.SmartProxy(); testProxy = new smartproxy.SmartProxy({});
}); });
tap.test('should start the testproxy', async () => { tap.test('should start the testproxy', async () => {
@ -12,10 +12,11 @@ tap.test('should start the testproxy', async () => {
}); });
tap.test('should supply reverse proxy config', async () => { tap.test('should supply reverse proxy config', async () => {
testProxy.updateReversConfigs([{ testProxy.updateReversConfigs([
{
destinationIp: 'localhost', destinationIp: 'localhost',
destinationPort: '8080', destinationPort: '3000',
hostName: 'central.eu', hostName: 'push.rocks',
privateKey: `-----BEGIN PRIVATE KEY----- privateKey: `-----BEGIN PRIVATE KEY-----
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+ 3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+
@ -97,11 +98,12 @@ r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g= JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
-----END CERTIFICATE----- -----END CERTIFICATE-----
` `
}]); }
]);
}); });
tap.test('should wait for 60 seconds', async tools => { tap.test('should wait for 60 seconds', async tools => {
await tools.delayFor(60000); await tools.delayFor(10000);
}); });
tap.test('should close the testproxy', async () => { tap.test('should close the testproxy', async () => {

View File

@ -3,16 +3,24 @@ import * as plugins from './smartproxy.plugins';
import { SmartproxyRouter } from './smartproxy.classes.router'; import { SmartproxyRouter } from './smartproxy.classes.router';
export class ProxyWorker { export class ProxyWorker {
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = []; public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
public httpsServer: plugins.https.Server; // | plugins.http.Server; public httpsServer: plugins.https.Server; // | plugins.http.Server;
public port = 8001; public port = 8001;
public router = new SmartproxyRouter(); public router = new SmartproxyRouter();
public socketMap = new plugins.lik.Objectmap<plugins.net.Socket>();
/** /**
* starts the proxyInstance * starts the proxyInstance
*/ */
public async start() { public async start() {
this.httpsServer = plugins.https.createServer({ this.httpsServer = plugins.https.createServer(
// ================
// Spotted this keypair in the code?
// Don't get exited:
// It is an invalid default keypair.
// For proper requests custom domain level keypairs are used that are provided in the reverse config
// ================
{
key: `-----BEGIN PRIVATE KEY----- key: `-----BEGIN PRIVATE KEY-----
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+ 3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+
@ -94,18 +102,78 @@ r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g= JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
-----END CERTIFICATE----- -----END CERTIFICATE-----
` `
}, async (req, res) => { },
async (req, res) => {
console.log('got request'); console.log('got request');
const destinationConfig = this.router.routeReq(req); const destinationConfig = this.router.routeReq(req);
// endRequest function
const endRequest = (
statusArg: number = 404,
messageArg: string = 'This route is not available on this server.',
headers: plugins.http.OutgoingHttpHeaders = {}
) => {
res.writeHead(statusArg, messageArg);
res.end(messageArg);
};
// authentication
if (destinationConfig.authentication) {
const authInfo = destinationConfig.authentication;
switch (authInfo.type) {
case 'Basic':
const authHeader = req.headers.authorization;
if (authHeader) {
if (!authHeader.includes('Basic ')) {
return endRequest(401, 'Authentication required', {
'WWW-Authenticate': 'Basic realm="Access to the staging site", charset="UTF-8"'
});
}
const authStringBase64 = req.headers.authorization.replace('Basic ', '');
const authString: string = plugins.smartstring.base64.decode(authStringBase64);
const userPassArray = authString.split(':');
const user = userPassArray[0];
const pass = userPassArray[1];
if (user === authInfo.user && pass === authInfo.pass) {
console.log('request successfully authenticated');
} else {
return endRequest(403, 'Forbidden: Wrong credentials');
}
}
break;
default:
return endRequest(
403,
'Forbidden: unsupported authentication method configured. Please report to the admin.'
);
}
}
let destinationUrl: string;
if (destinationConfig) {
destinationUrl = `http://${destinationConfig.destinationIp}:${destinationConfig.destinationPort}${req.url}`;
} else {
return endRequest();
}
console.log(destinationUrl);
const response = await plugins.smartrequest.request( const response = await plugins.smartrequest.request(
`http://${destinationConfig.destinationIp}:${destinationConfig.destinationPort}${req.url}`, destinationUrl,
{ {
method: req.method, method: req.method,
headers: req.headers headers: req.headers
}, },
true // lets make this streaming true, // lets make this streaming
request => {
req.on('data', data => {
request.write(data);
});
req.on('end', data => {
request.end();
});
}
); );
res.statusCode = response.statusCode; res.statusCode = response.statusCode;
console.log(response.statusCode);
for (const header of Object.keys(response.headers)) { for (const header of Object.keys(response.headers)) {
res.setHeader(header, response.headers[header]); res.setHeader(header, response.headers[header]);
} }
@ -115,17 +183,20 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
response.on('end', () => { response.on('end', () => {
res.end(); res.end();
}); });
}); }
);
const Websocket = await import('ws');
// Enable websockets // Enable websockets
const wss = new plugins.ws.Server({ server: this.httpsServer }); const wss = new plugins.ws.Server({ server: this.httpsServer });
wss.on('connection', function connection(ws) { wss.on('connection', (ws: plugins.wsDefault) => {
console.log('got connection for wsc'); console.log('got connection for wsc');
const wscConnected = plugins.smartpromise.defer(); const wscConnected = plugins.smartpromise.defer();
const wsc = new Websocket.default(`${ws.url}`); const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
headers: {
Host: ws.url
}
});
wsc.on('open', () => { wsc.on('open', () => {
wscConnected.resolve(); wscConnected.resolve();
}); });
@ -146,19 +217,28 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
ws.close(); ws.close();
}); });
}); });
this.httpsServer.keepAliveTimeout = 61000;
this.httpsServer.headersTimeout = 65000;
this.httpsServer.on('connection', connection => {
this.socketMap.add(connection);
connection.on('close', () => {
this.socketMap.remove(connection);
});
});
this.httpsServer.listen(this.port); this.httpsServer.listen(this.port);
console.log(`OK: now listening for new connections on port ${this.port}`); console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.port}`);
} }
public async updateCandidates(arrayOfReverseCandidates: plugins.tsclass.IReverseProxyConfig[]) { public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.hostCandidates = arrayOfReverseCandidates; this.proxyConfigs = proxyConfigsArg;
this.router.setNewCandidates(arrayOfReverseCandidates); this.router.setNewProxyConfigs(proxyConfigsArg);
for (const hostCandidate of this.hostCandidates) { for (const hostCandidate of this.proxyConfigs) {
// console.log(hostCandidate); // console.log(hostCandidate);
this.httpsServer.addContext(hostCandidate.hostName, { this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey, cert: hostCandidate.publicKey,
key: hostCandidate.privateKey, key: hostCandidate.privateKey
}); });
} }
/* this.httpsServer.close(); /* this.httpsServer.close();
@ -170,6 +250,9 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
this.httpsServer.close(() => { this.httpsServer.close(() => {
done.resolve(); done.resolve();
}); });
await this.socketMap.forEach(async socket => {
socket.destroy();
});
await done.promise; await done.promise;
} }
} }
@ -185,7 +268,7 @@ const proxyWorkerCalls = {
await proxyWorkerInstance.start(); await proxyWorkerInstance.start();
}, },
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => { updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
await proxyWorkerInstance.updateCandidates(configArray); await proxyWorkerInstance.updateProxyConfigs(configArray);
} }
}; };

View File

@ -1,20 +1,32 @@
import * as plugins from './smartproxy.plugins'; import * as plugins from './smartproxy.plugins';
export class SmartproxyRouter { export class SmartproxyRouter {
public reverseCandidates: plugins.tsclass.network.IReverseProxyConfig[] = []; public reverseProxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
/** /**
* sets a new set of reverse configs to be routed to * sets a new set of reverse configs to be routed to
* @param reverseCandidatesArg * @param reverseCandidatesArg
*/ */
public setNewCandidates(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) { public setNewProxyConfigs(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.reverseCandidates = reverseCandidatesArg; this.reverseProxyConfigs = reverseCandidatesArg;
} }
/**
* routes a request
*/
public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig { public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig {
const originalHost = req.headers.host; const originalHost = req.headers.host;
const correspodingReverseProxyConfig = this.reverseCandidates.find(reverseConfig => { const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => {
return reverseConfig.hostName === originalHost; return reverseConfig.hostName === originalHost;
}); });
return correspodingReverseProxyConfig; return correspodingReverseProxyConfig;
} }
public routeWs(ws: plugins.wsDefault) {
const originalHost = plugins.url.parse(ws.url).host;
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => {
return reverseConfig.hostName === originalHost;
});
return correspodingReverseProxyConfig.destinationIp;
}
} }

View File

@ -3,13 +3,23 @@ import * as plugins from './smartproxy.plugins';
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker'; import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
import { TPortProxyCalls } from './smartproxy.portproxy'; import { TPortProxyCalls } from './smartproxy.portproxy';
export interface ISmartProxyOptions {
port?: number;
}
export class SmartProxy { export class SmartProxy {
public smartsystem = new plugins.smartsystem.Smartsystem(); public smartsystem = new plugins.smartsystem.Smartsystem();
public reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = []; public reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
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( public options: ISmartProxyOptions;
constructor(optionsArg: ISmartProxyOptions = {}) {
this.options = optionsArg;
}
public async updateReverseConfigs(
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[] reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
) { ) {
// TODO search for old hostCandidates with that target // TODO search for old hostCandidates with that target
@ -28,6 +38,8 @@ export class SmartProxy {
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>( this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
new plugins.smartspawn.Worker('./smartproxy.portproxy') new plugins.smartspawn.Worker('./smartproxy.portproxy')
); );
await this.portProxyFunctions.start(this.options.port);
await this.proxyWorkerFunctions.start(); await this.proxyWorkerFunctions.start();
console.log('successfully spawned portproxy and proxyworkers!'); console.log('successfully spawned portproxy and proxyworkers!');

View File

@ -1,8 +1,10 @@
// node native scope // node native scope
import * as http from 'http'; import * as http from 'http';
import * as https from 'https'; import * as https from 'https';
import * as net from 'net';
import * as url from 'url';
export { http, https }; export { http, https, net, url };
// tsclass scope // tsclass scope
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
@ -10,14 +12,17 @@ import * as tsclass from '@tsclass/tsclass';
export { tsclass }; export { tsclass };
// pushrocks scope // pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
import * as smartspawn from '@pushrocks/smartspawn'; import * as smartspawn from '@pushrocks/smartspawn';
import * as smartstring from '@pushrocks/smartstring';
import * as smartsystem from '@pushrocks/smartsystem'; import * as smartsystem from '@pushrocks/smartsystem';
export { smartrequest, smartpromise, smartspawn, smartsystem }; export { lik, smartrequest, smartpromise, smartspawn, smartstring, smartsystem };
// third party scope // third party scope
import * as ws from 'ws'; import * as ws from 'ws';
import wsDefault from 'ws';
export { ws }; export { wsDefault, ws };

View File

@ -1,7 +1,11 @@
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 let netServer: plugins.net.Server;
const portProxyCalls = {
start: async (portArg = 8000) => {
netServer = net
.createServer(from => { .createServer(from => {
const to = net.createConnection({ const to = net.createConnection({
host: 'localhost', host: 'localhost',
@ -10,12 +14,12 @@ const server = net
from.pipe(to); from.pipe(to);
to.pipe(from); to.pipe(from);
}) })
.listen(8000); .listen(portArg);
console.log(`PortProxy -> OK: Now listening on port ${portArg}`);
const portProxyCalls = { },
stop: async () => { stop: async () => {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
server.close(() => { netServer.close(() => {
done.resolve(); done.resolve();
}); });
await done.promise; await done.promise;