Compare commits
60 Commits
Author | SHA1 | Date | |
---|---|---|---|
ca55d06244 | |||
7284924b26 | |||
10857aa12b | |||
c968c7f844 | |||
b07015f6c4 | |||
ca4ddade17 | |||
17eaea4124 | |||
d3d8f6ff57 | |||
906661c7f4 | |||
ea46caebb7 | |||
973e896fbf | |||
4605035b01 | |||
1e4e2c4ab6 | |||
30896b045f | |||
08f382b9fa | |||
1629dc1f5a | |||
b33acdea41 | |||
101470dcd4 | |||
ca73849541 | |||
b64523b0b2 | |||
963ad6efa4 | |||
d271029302 | |||
018fcbf71e | |||
fa04732241 | |||
da19fab8d8 | |||
8d318dca28 | |||
d03bfcc793 | |||
4ba2686977 | |||
d24c4d4b7a | |||
e1d4d6cf38 | |||
11344ac0df | |||
85fcfc3c36 | |||
e9ac7b2347 | |||
2c59540768 | |||
0f82d63f5c | |||
b5fcdadd3d | |||
6168b07414 | |||
588179335a | |||
703cbedad4 | |||
dd7e9e8416 | |||
da060fa986 | |||
df001e13f3 | |||
ef7e54be34 | |||
d800b6ed6e | |||
af42598464 | |||
93b1048cb7 | |||
29549b126e | |||
736113eb4e | |||
3b2d140836 | |||
70690f6400 | |||
ae561e3e88 | |||
8a02a0c506 | |||
58ec01526a | |||
1c3619040c | |||
0eabdcde28 | |||
3f935b3a03 | |||
c7b8b6ff66 | |||
a9815c61d2 | |||
82730877ce | |||
b68b143a3f |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
113
.gitlab-ci.yml
113
.gitlab-ci.yml
@ -1,40 +1,46 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
variables:
|
||||
GIT_STRATEGY: clone
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- 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
|
||||
- notpriv
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -43,37 +49,36 @@ snyk:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
@ -81,35 +86,37 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:18-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -117,5 +124,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal 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", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartproxy",
|
||||
"shortDescription": "a proxy for handling high workloads of proxying",
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"npmPackagename": "@pushrocks/smartproxy",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
|
15736
package-lock.json
generated
15736
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
55
package.json
55
package.json
@ -1,46 +1,47 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.33",
|
||||
"version": "3.0.7",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)",
|
||||
"format": "(gitzone format)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"format": "(gitzone format)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.12.5",
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^3.0.11",
|
||||
"@pushrocks/smartnetwork": "^1.1.14",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartrequest": "^1.1.42",
|
||||
"@pushrocks/smartspawn": "^2.0.9",
|
||||
"@pushrocks/smartstring": "^3.0.14",
|
||||
"@pushrocks/smartsystem": "^2.0.9",
|
||||
"@tsclass/tsclass": "^2.0.13",
|
||||
"@types/ws": "^6.0.3",
|
||||
"ws": "^7.2.0"
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^2.0.0",
|
||||
"@pushrocks/smartstring": "^4.0.2",
|
||||
"@tsclass/tsclass": "^4.0.17",
|
||||
"@types/ws": "^8.5.3",
|
||||
"ws": "^8.8.1"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
29
readme.md
29
readme.md
@ -8,16 +8,31 @@ a proxy for handling high workloads of proxying
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartproxy/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartproxy/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartproxy/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartproxy)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartproxy)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## 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
|
||||
|
||||
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.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
|
31
test/test.ts
31
test/test.ts
@ -1,10 +1,13 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartproxy from '../ts/index';
|
||||
import * as smartproxy from '../ts/index.js';
|
||||
|
||||
let testProxy: smartproxy.SmartProxy;
|
||||
let testProxy: smartproxy.NetworkProxy;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
testProxy = new smartproxy.SmartProxy();
|
||||
testProxy = new smartproxy.NetworkProxy({
|
||||
port: 3001,
|
||||
});
|
||||
expect(testProxy).toBeInstanceOf(smartproxy.NetworkProxy);
|
||||
});
|
||||
|
||||
tap.test('should start the testproxy', async () => {
|
||||
@ -12,11 +15,12 @@ tap.test('should start the testproxy', async () => {
|
||||
});
|
||||
|
||||
tap.test('should supply reverse proxy config', async () => {
|
||||
testProxy.updateReversConfigs([{
|
||||
destinationIp: 'localhost',
|
||||
destinationPort: '3000',
|
||||
hostName: 'central.eu',
|
||||
privateKey: `-----BEGIN PRIVATE KEY-----
|
||||
testProxy.updateProxyConfigs([
|
||||
{
|
||||
destinationIp: '127.0.0.1',
|
||||
destinationPort: '3000',
|
||||
hostName: 'push.rocks',
|
||||
privateKey: `-----BEGIN PRIVATE KEY-----
|
||||
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
|
||||
3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+
|
||||
kQlHug1Cx+LFssvz+hLlB5cqJQZfRKx92DhbROygtxG9r7UBmx/fwx+JQ+HOHX9R
|
||||
@ -69,7 +73,7 @@ h+7fBVO49PLL0NWy+8GT8y7a04calFfLvZEA2UMaunBis3dE1KMFfJL/0JO+sKnF
|
||||
2TkK01XDDJURK5Lhuvc7WrK2rSJ/fK+0GA==
|
||||
-----END PRIVATE KEY-----
|
||||
`,
|
||||
publicKey: `-----BEGIN CERTIFICATE-----
|
||||
publicKey: `-----BEGIN CERTIFICATE-----
|
||||
MIIEljCCAn4CCQDY+ZbC9FASVjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJE
|
||||
RTAeFw0xOTA5MjAxNjAxNDRaFw0yMDA5MTkxNjAxNDRaMA0xCzAJBgNVBAYTAkRF
|
||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA4thf9JEK/epoXt8hFr8t
|
||||
@ -96,12 +100,13 @@ TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
|
||||
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
|
||||
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
-----END CERTIFICATE-----
|
||||
`
|
||||
}]);
|
||||
`,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
tap.test('should wait for 60 seconds', async tools => {
|
||||
await tools.delayFor(60000);
|
||||
tap.test('should wait for 60 seconds', async (tools) => {
|
||||
await tools.delayFor(10000);
|
||||
});
|
||||
|
||||
tap.test('should close the testproxy', async () => {
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartproxy',
|
||||
version: '3.0.7',
|
||||
description: 'a proxy for handling high workloads of proxying'
|
||||
}
|
@ -1 +1,3 @@
|
||||
export * from './smartproxy.classes.smartproxy';
|
||||
export * from './smartproxy.classes.networkproxy.js';
|
||||
export * from './smartproxy.portproxy.js';
|
||||
export * from './smartproxy.classes.sslredirect.js'
|
@ -1,19 +1,38 @@
|
||||
import { expose } from '@pushrocks/smartspawn';
|
||||
import * as plugins from './smartproxy.plugins';
|
||||
import { SmartproxyRouter } from './smartproxy.classes.router';
|
||||
import * as plugins from './smartproxy.plugins.js';
|
||||
import { ProxyRouter } from './smartproxy.classes.router.js';
|
||||
|
||||
export class ProxyWorker {
|
||||
export interface INetworkProxyOptions {
|
||||
port: number;
|
||||
}
|
||||
|
||||
export class NetworkProxy {
|
||||
// INSTANCE
|
||||
public options: INetworkProxyOptions;
|
||||
public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||
public httpsServer: plugins.https.Server; // | plugins.http.Server;
|
||||
public port = 8001;
|
||||
public router = new SmartproxyRouter();
|
||||
public socketMap = new plugins.lik.Objectmap<plugins.net.Socket>();
|
||||
public httpsServer: plugins.https.Server;
|
||||
public router = new ProxyRouter();
|
||||
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
|
||||
public defaultHeaders: { [key: string]: string } = {};
|
||||
|
||||
public alreadyAddedReverseConfigs: {
|
||||
[hostName: string]: plugins.tsclass.network.IReverseProxyConfig;
|
||||
} = {};
|
||||
|
||||
constructor(optionsArg: INetworkProxyOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the proxyInstance
|
||||
*/
|
||||
public async start() {
|
||||
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-----
|
||||
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
|
||||
@ -95,13 +114,16 @@ TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
|
||||
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
|
||||
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
-----END CERTIFICATE-----
|
||||
`
|
||||
`,
|
||||
},
|
||||
async (req, res) => {
|
||||
console.log('got request');
|
||||
const destinationConfig = this.router.routeReq(req);
|
||||
|
||||
// endRequest function
|
||||
/**
|
||||
* endRequest function
|
||||
* can be used to prematurely end a request
|
||||
*/
|
||||
const endRequest = (
|
||||
statusArg: number = 404,
|
||||
messageArg: string = 'This route is not available on this server.',
|
||||
@ -120,7 +142,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
if (authHeader) {
|
||||
if (!authHeader.includes('Basic ')) {
|
||||
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 ', '');
|
||||
@ -154,24 +176,28 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
destinationUrl,
|
||||
{
|
||||
method: req.method,
|
||||
headers: req.headers
|
||||
headers: req.headers,
|
||||
keepAlive: true,
|
||||
},
|
||||
true, // lets make this streaming
|
||||
request => {
|
||||
req.on('data', data => {
|
||||
(request) => {
|
||||
req.on('data', (data) => {
|
||||
request.write(data);
|
||||
});
|
||||
req.on('end', data => {
|
||||
req.on('end', (data) => {
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
);
|
||||
res.statusCode = 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)) {
|
||||
res.setHeader(header, response.headers[header]);
|
||||
}
|
||||
response.on('data', data => {
|
||||
response.on('data', (data) => {
|
||||
res.write(data);
|
||||
});
|
||||
response.on('end', () => {
|
||||
@ -181,62 +207,112 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
);
|
||||
|
||||
// Enable websockets
|
||||
const wss = new plugins.ws.Server({ server: this.httpsServer });
|
||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||
wss.on('connection', (ws: plugins.wsDefault) => {
|
||||
console.log('got connection for wsc');
|
||||
const wscConnected = plugins.smartpromise.defer();
|
||||
|
||||
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
|
||||
headers: {
|
||||
Host: ws.url
|
||||
}
|
||||
Host: ws.url,
|
||||
},
|
||||
});
|
||||
wsc.on('open', () => {
|
||||
wscConnected.resolve();
|
||||
});
|
||||
|
||||
ws.on('message', async message => {
|
||||
ws.on('message', async (message) => {
|
||||
await wscConnected.promise;
|
||||
wsc.emit('message', message);
|
||||
});
|
||||
wsc.on('message', message => {
|
||||
wsc.on('message', (message) => {
|
||||
ws.emit('message', message);
|
||||
});
|
||||
|
||||
// handle closing
|
||||
ws.on('close', message => {
|
||||
wsc.close();
|
||||
});
|
||||
wsc.on('close', message => {
|
||||
const cleanUp = () => {
|
||||
ws.removeAllListeners();
|
||||
ws.close();
|
||||
ws.terminate();
|
||||
wsc.removeAllListeners();
|
||||
wsc.close();
|
||||
wsc.terminate();
|
||||
};
|
||||
|
||||
ws.on('close', (message) => {
|
||||
cleanUp();
|
||||
});
|
||||
wsc.on('close', (message) => {
|
||||
cleanUp();
|
||||
});
|
||||
});
|
||||
this.httpsServer.keepAliveTimeout = 61000;
|
||||
this.httpsServer.headersTimeout = 65000;
|
||||
|
||||
this.httpsServer.on('connection', connection => {
|
||||
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
||||
connection.setTimeout(120000);
|
||||
this.socketMap.add(connection);
|
||||
const cleanupConnection = () => {
|
||||
if (this.socketMap.checkForObject(connection)) {
|
||||
this.socketMap.remove(connection);
|
||||
connection.end();
|
||||
connection.removeAllListeners();
|
||||
connection.destroy();
|
||||
}
|
||||
};
|
||||
connection.on('close', () => {
|
||||
this.socketMap.remove(connection);
|
||||
cleanupConnection();
|
||||
});
|
||||
connection.on('error', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
connection.on('end', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
connection.on('timeout', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
});
|
||||
|
||||
this.httpsServer.listen(this.port);
|
||||
console.log(`OK: now listening for new connections on port ${this.port}`);
|
||||
this.httpsServer.listen(this.options.port);
|
||||
console.log(
|
||||
`ProxyWorker -> OK: now listening for new connections on port ${this.options.port}`
|
||||
);
|
||||
}
|
||||
|
||||
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.IReverseProxyConfig[]) {
|
||||
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
||||
this.proxyConfigs = proxyConfigsArg;
|
||||
this.router.setNewProxyConfigs(proxyConfigsArg);
|
||||
for (const hostCandidate of this.proxyConfigs) {
|
||||
// console.log(hostCandidate);
|
||||
|
||||
const existingHostNameConfig = this.alreadyAddedReverseConfigs[hostCandidate.hostName];
|
||||
|
||||
if (!existingHostNameConfig) {
|
||||
this.alreadyAddedReverseConfigs[hostCandidate.hostName] = hostCandidate;
|
||||
} else {
|
||||
if (
|
||||
existingHostNameConfig.publicKey === hostCandidate.publicKey &&
|
||||
existingHostNameConfig.privateKey === hostCandidate.privateKey
|
||||
) {
|
||||
continue;
|
||||
} else {
|
||||
this.alreadyAddedReverseConfigs[hostCandidate.hostName] = hostCandidate;
|
||||
}
|
||||
}
|
||||
|
||||
this.httpsServer.addContext(hostCandidate.hostName, {
|
||||
cert: hostCandidate.publicKey,
|
||||
key: hostCandidate.privateKey
|
||||
key: hostCandidate.privateKey,
|
||||
});
|
||||
this.httpsServer;
|
||||
}
|
||||
}
|
||||
|
||||
public async addDefaultHeaders(headersArg: { [key: string]: string }) {
|
||||
for (const headerKey of Object.keys(headersArg)) {
|
||||
this.defaultHeaders[headerKey] = headersArg[headerKey];
|
||||
}
|
||||
/* this.httpsServer.close();
|
||||
this.httpsServer.listen(this.port); */
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
@ -244,28 +320,9 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
this.httpsServer.close(() => {
|
||||
done.resolve();
|
||||
});
|
||||
await this.socketMap.forEach(async socket => {
|
||||
await this.socketMap.forEach(async (socket) => {
|
||||
socket.destroy();
|
||||
});
|
||||
await done.promise;
|
||||
}
|
||||
}
|
||||
|
||||
const proxyWorkerInstance = new ProxyWorker();
|
||||
|
||||
// the following is interesting for the master process only
|
||||
const proxyWorkerCalls = {
|
||||
stop: async () => {
|
||||
await proxyWorkerInstance.stop();
|
||||
},
|
||||
start: async () => {
|
||||
await proxyWorkerInstance.start();
|
||||
},
|
||||
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
||||
await proxyWorkerInstance.updateProxyConfigs(configArray);
|
||||
}
|
||||
};
|
||||
|
||||
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
|
||||
expose(proxyWorkerCalls);
|
||||
console.log('ProxyWorker initialized');
|
@ -1,6 +1,6 @@
|
||||
import * as plugins from './smartproxy.plugins';
|
||||
import * as plugins from './smartproxy.plugins.js';
|
||||
|
||||
export class SmartproxyRouter {
|
||||
export class ProxyRouter {
|
||||
public reverseProxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||
|
||||
/**
|
||||
@ -16,7 +16,7 @@ export class SmartproxyRouter {
|
||||
*/
|
||||
public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig {
|
||||
const originalHost = req.headers.host;
|
||||
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => {
|
||||
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find((reverseConfig) => {
|
||||
return reverseConfig.hostName === originalHost;
|
||||
});
|
||||
return correspodingReverseProxyConfig;
|
||||
@ -24,7 +24,7 @@ export class SmartproxyRouter {
|
||||
|
||||
public routeWs(ws: plugins.wsDefault) {
|
||||
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 correspodingReverseProxyConfig.destinationIp;
|
||||
|
@ -1,45 +0,0 @@
|
||||
import * as plugins from './smartproxy.plugins';
|
||||
|
||||
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
|
||||
import { TPortProxyCalls } from './smartproxy.portproxy';
|
||||
|
||||
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 async updateReversConfigs(
|
||||
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
|
||||
) {
|
||||
// TODO search for old hostCandidates with that target
|
||||
this.reverseConfigs = reverseConfigsArg;
|
||||
if (this.proxyWorkerFunctions) {
|
||||
await this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
|
||||
}
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(
|
||||
new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker')
|
||||
);
|
||||
this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
|
||||
|
||||
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
|
||||
new plugins.smartspawn.Worker('./smartproxy.portproxy')
|
||||
);
|
||||
await this.proxyWorkerFunctions.start();
|
||||
|
||||
console.log('successfully spawned portproxy and proxyworkers!');
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.proxyWorkerFunctions.stop();
|
||||
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);
|
||||
console.log('proxy worker stopped');
|
||||
await this.portProxyFunctions.stop();
|
||||
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
|
||||
console.log('portproxy stopped');
|
||||
console.log('Terminated all childs!');
|
||||
}
|
||||
}
|
32
ts/smartproxy.classes.sslredirect.ts
Normal file
32
ts/smartproxy.classes.sslredirect.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as plugins from './smartproxy.plugins.js';
|
||||
|
||||
export class SslRedirect {
|
||||
httpServer: plugins.http.Server;
|
||||
port: number;
|
||||
constructor(portArg: number) {
|
||||
this.port = portArg;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.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();
|
||||
});
|
||||
this.httpServer.listen(this.port);
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
this.httpServer.close(() => {
|
||||
done.resolve();
|
||||
});
|
||||
await done.promise;
|
||||
}
|
||||
}
|
@ -15,11 +15,9 @@ export { tsclass };
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartspawn from '@pushrocks/smartspawn';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
import * as smartsystem from '@pushrocks/smartsystem';
|
||||
|
||||
export { lik, smartrequest, smartpromise, smartspawn, smartstring, smartsystem };
|
||||
export { lik, smartrequest, smartpromise, smartstring };
|
||||
|
||||
// third party scope
|
||||
import * as ws from 'ws';
|
||||
|
@ -1,28 +1,70 @@
|
||||
import * as plugins from './smartproxy.plugins';
|
||||
import { expose } from '@pushrocks/smartspawn';
|
||||
import * as plugins from './smartproxy.plugins.js';
|
||||
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);
|
||||
|
||||
const portProxyCalls = {
|
||||
stop: async () => {
|
||||
export class PortProxy {
|
||||
netServer: plugins.net.Server;
|
||||
fromPort: number;
|
||||
toPort: number;
|
||||
|
||||
constructor(fromPortArg: number, toPortArg: number) {
|
||||
this.fromPort = fromPortArg;
|
||||
this.toPort = toPortArg;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
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();
|
||||
};
|
||||
this.netServer = net
|
||||
.createServer((from) => {
|
||||
const to = net.createConnection({
|
||||
host: 'localhost',
|
||||
port: this.toPort,
|
||||
});
|
||||
from.setTimeout(120000);
|
||||
from.pipe(to);
|
||||
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(this.fromPort);
|
||||
console.log(`PortProxy -> OK: Now listening on port ${this.fromPort}`);
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
server.close(() => {
|
||||
this.netServer.close(() => {
|
||||
done.resolve();
|
||||
});
|
||||
await done.promise;
|
||||
}
|
||||
};
|
||||
|
||||
export type TPortProxyCalls = typeof portProxyCalls;
|
||||
expose(portProxyCalls);
|
||||
|
||||
console.log('PortProxy Initialized');
|
||||
}
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user