Compare commits

...

22 Commits

Author SHA1 Message Date
11344ac0df 2.0.9 2021-02-03 00:23:29 +00:00
85fcfc3c36 fix(core): update 2021-02-03 00:23:28 +00:00
e9ac7b2347 2.0.8 2021-02-03 00:16:11 +00:00
2c59540768 fix(core): update 2021-02-03 00:16:11 +00:00
0f82d63f5c 2.0.7 2021-02-03 00:13:30 +00:00
b5fcdadd3d fix(core): update 2021-02-03 00:13:29 +00:00
6168b07414 2.0.6 2021-02-02 21:59:55 +00:00
588179335a fix(core): update 2021-02-02 21:59:54 +00:00
703cbedad4 2.0.5 2021-02-02 21:59:25 +00:00
dd7e9e8416 fix(core): update 2021-02-02 21:59:24 +00:00
da060fa986 2.0.4 2021-02-02 15:55:26 +00:00
df001e13f3 fix(core): update 2021-02-02 15:55:25 +00:00
ef7e54be34 2.0.3 2021-02-02 00:53:58 +00:00
d800b6ed6e fix(core): update 2021-02-02 00:53:57 +00:00
af42598464 2.0.2 2020-02-23 19:04:53 +00:00
93b1048cb7 fix(core): update 2020-02-23 19:04:53 +00:00
29549b126e 2.0.1 2020-02-23 19:03:26 +00:00
736113eb4e fix(core): update 2020-02-23 19:03:25 +00:00
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
11 changed files with 10092 additions and 1048 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@ -19,22 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -49,9 +62,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -62,9 +73,7 @@ testBuild:
- 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
release: release:
stage: release stage: release
@ -84,6 +93,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

11188
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "1.0.37", "version": "2.0.9",
"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_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -13,34 +13,38 @@
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.0", "@pushrocks/tapbundle": "^3.2.10",
"@types/node": "^13.7.0", "@types/node": "^14.14.22",
"tslint": "^6.0.0", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.16", "@pushrocks/lik": "^4.0.20",
"@pushrocks/smartnetwork": "^1.1.18", "@pushrocks/smartnetwork": "^1.1.22",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrequest": "^1.1.47", "@pushrocks/smartrequest": "^1.1.51",
"@pushrocks/smartspawn": "^2.0.9", "@pushrocks/smartspawn": "^2.0.9",
"@pushrocks/smartstring": "^3.0.18", "@pushrocks/smartstring": "^3.0.24",
"@pushrocks/smartsystem": "^2.0.9", "@pushrocks/smartsystem": "^2.0.9",
"@tsclass/tsclass": "^3.0.3", "@tsclass/tsclass": "^3.0.29",
"@types/ws": "^7.2.1", "@types/ws": "^7.4.0",
"ws": "^7.2.1" "ws": "^7.4.2"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@ -8,16 +8,26 @@ 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
[![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) Status Category | Status Badge
[![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) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartproxy/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartproxy/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartproxy)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartproxy)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartproxy)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartproxy)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartproxy)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## 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). :)
## Contribution ## Contribution

View File

@ -12,7 +12,7 @@ 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.updateReverseConfigs([
{ {
destinationIp: 'localhost', destinationIp: 'localhost',
destinationPort: '3000', destinationPort: '3000',
@ -97,12 +97,12 @@ TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS 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(10000); await tools.delayFor(10000);
}); });

View File

@ -7,7 +7,8 @@ export class ProxyWorker {
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>(); public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
public defaultHeaders: {[key: string]: string} = {};
/** /**
* starts the proxyInstance * starts the proxyInstance
@ -101,7 +102,7 @@ TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS 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');
@ -126,7 +127,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
if (authHeader) { if (authHeader) {
if (!authHeader.includes('Basic ')) { if (!authHeader.includes('Basic ')) {
return endRequest(401, 'Authentication required', { return endRequest(401, 'Authentication required', {
'WWW-Authenticate': 'Basic realm="Access to the staging site", charset="UTF-8"' 'WWW-Authenticate': 'Basic realm="Access to the staging site", charset="UTF-8"',
}); });
} }
const authStringBase64 = req.headers.authorization.replace('Basic ', ''); const authStringBase64 = req.headers.authorization.replace('Basic ', '');
@ -160,24 +161,27 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
destinationUrl, destinationUrl,
{ {
method: req.method, method: req.method,
headers: req.headers headers: req.headers,
}, },
true, // lets make this streaming true, // lets make this streaming
request => { (request) => {
req.on('data', data => { req.on('data', (data) => {
request.write(data); request.write(data);
}); });
req.on('end', data => { req.on('end', (data) => {
request.end(); request.end();
}); });
} }
); );
res.statusCode = response.statusCode; res.statusCode = response.statusCode;
console.log(response.statusCode); console.log(response.statusCode);
for (const defaultHeader of Object.keys(this.defaultHeaders)) {
res.setHeader(defaultHeader, this.defaultHeaders[defaultHeader]);
}
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]);
} }
response.on('data', data => { response.on('data', (data) => {
res.write(data); res.write(data);
}); });
response.on('end', () => { response.on('end', () => {
@ -194,33 +198,33 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
const wsc = new plugins.wsDefault(this.router.routeWs(ws), { const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
headers: { headers: {
Host: ws.url Host: ws.url,
} },
}); });
wsc.on('open', () => { wsc.on('open', () => {
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();
}); });
}); });
this.httpsServer.keepAliveTimeout = 61000; this.httpsServer.keepAliveTimeout = 61000;
this.httpsServer.headersTimeout = 65000; this.httpsServer.headersTimeout = 65000;
this.httpsServer.on('connection', connection => { this.httpsServer.on('connection', (connection) => {
this.socketMap.add(connection); this.socketMap.add(connection);
connection.on('close', () => { connection.on('close', () => {
this.socketMap.remove(connection); this.socketMap.remove(connection);
@ -231,14 +235,14 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
console.log(`ProxyWorker -> 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 updateProxyConfigs(proxyConfigsArg: plugins.tsclass.IReverseProxyConfig[]) { public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.proxyConfigs = proxyConfigsArg; this.proxyConfigs = proxyConfigsArg;
this.router.setNewProxyConfigs(proxyConfigsArg); this.router.setNewProxyConfigs(proxyConfigsArg);
for (const hostCandidate of this.proxyConfigs) { 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();
@ -250,7 +254,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
this.httpsServer.close(() => { this.httpsServer.close(() => {
done.resolve(); done.resolve();
}); });
await this.socketMap.forEach(async socket => { await this.socketMap.forEach(async (socket) => {
socket.destroy(); socket.destroy();
}); });
await done.promise; await done.promise;
@ -269,7 +273,8 @@ const proxyWorkerCalls = {
}, },
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => { updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
await proxyWorkerInstance.updateProxyConfigs(configArray); await proxyWorkerInstance.updateProxyConfigs(configArray);
} },
addDefaultHeaders: async (headers: {[key: string]: string}) => {}
}; };
export type TProxyWorkerCalls = typeof proxyWorkerCalls; export type TProxyWorkerCalls = typeof proxyWorkerCalls;

View File

@ -16,7 +16,7 @@ export class SmartproxyRouter {
*/ */
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.reverseProxyConfigs.find(reverseConfig => { const correspodingReverseProxyConfig = this.reverseProxyConfigs.find((reverseConfig) => {
return reverseConfig.hostName === originalHost; return reverseConfig.hostName === originalHost;
}); });
return correspodingReverseProxyConfig; return correspodingReverseProxyConfig;
@ -24,7 +24,7 @@ export class SmartproxyRouter {
public routeWs(ws: plugins.wsDefault) { public routeWs(ws: plugins.wsDefault) {
const originalHost = plugins.url.parse(ws.url).host; const originalHost = plugins.url.parse(ws.url).host;
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => { const correspodingReverseProxyConfig = this.reverseProxyConfigs.find((reverseConfig) => {
return reverseConfig.hostName === originalHost; return reverseConfig.hostName === originalHost;
}); });
return correspodingReverseProxyConfig.destinationIp; return correspodingReverseProxyConfig.destinationIp;

View File

@ -19,7 +19,7 @@ export class SmartProxy {
this.options = optionsArg; this.options = optionsArg;
} }
public async updateReversConfigs( 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

View File

@ -2,28 +2,78 @@ 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';
let netServer: plugins.net.Server; let netServer: plugins.net.Server;
let httpServer: plugins.http.Server;
const portProxyCalls = { const portProxyCalls = {
start: async (portArg = 8000) => { start: async (portArg = 8000) => {
httpServer = plugins.http.createServer((request, response) => {
const requestUrl = new URL(request.url, `http://${request.headers.host}`);
const completeUrlWithoutProtocol = `${requestUrl.host}${requestUrl.pathname}${requestUrl.search}`;
const redirectUrl = `https://${completeUrlWithoutProtocol}`;
console.log(`Got http request for http://${completeUrlWithoutProtocol}`);
console.log(`Redirecting to ${redirectUrl}`);
response.writeHead(302, {
Location: redirectUrl,
});
response.end();
});
httpServer.listen(7999);
const cleanUpSockets = (from: plugins.net.Socket, to: plugins.net.Socket) => {
from.end();
to.end();
from.removeAllListeners();
to.removeAllListeners();
from.unpipe();
to.unpipe();
from.destroy();
to.destroy();
}
netServer = net netServer = net
.createServer(from => { .createServer((from) => {
const to = net.createConnection({ const to = net.createConnection({
host: 'localhost', host: 'localhost',
port: 8001 port: 8001,
}); });
from.setTimeout(120000);
from.pipe(to); from.pipe(to);
to.pipe(from); to.pipe(from);
from.on('error', () => {
cleanUpSockets(from, to);
});
to.on('error', () => {
cleanUpSockets(from, to);
});
from.on('close', () => {
cleanUpSockets(from, to);
});
to.on('close', () => {
cleanUpSockets(from, to);
});
from.on('timeout', () => {
cleanUpSockets(from, to);
});
to.on('timeout', () => {
cleanUpSockets(from, to);
});
from.on('end', () => {
cleanUpSockets(from, to);
})
to.on('end', () => {
cleanUpSockets(from, to);
})
}) })
.listen(portArg); .listen(portArg);
console.log(`PortProxy -> OK: Now listening on port ${portArg}`); console.log(`PortProxy -> OK: Now listening on port ${portArg}`);
}, },
stop: async () => { stop: async () => {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
httpServer.close(() => {
netServer.close(() => { netServer.close(() => {
done.resolve(); done.resolve();
}); });
});
await done.promise; await done.promise;
} },
}; };
export type TPortProxyCalls = typeof portProxyCalls; export type TPortProxyCalls = typeof portProxyCalls;