Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
3e7416574d | |||
7f843bef50 | |||
360c31c6b6 | |||
4ca748ec93 | |||
6dd3e473c6 | |||
3856a1d7fb | |||
fb76ecfd8a | |||
6c84406574 | |||
945065279f | |||
07a8d9bec6 | |||
2c55a6b819 | |||
8f4421fbc3 | |||
5eebc434bb | |||
ed03c3ec4b | |||
06808cb2c9 | |||
ba3d4d4240 | |||
9c49b9a9e5 | |||
f7259a6309 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -1,18 +1,16 @@
|
|||||||
# 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
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -21,20 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
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 -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
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
|
# test stage
|
||||||
@ -50,28 +63,27 @@ testStable:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
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:
|
||||||
- docker
|
- docker
|
||||||
- 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
|
||||||
|
|
||||||
@ -81,11 +93,15 @@ 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 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 +112,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
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,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
11350
package-lock.json
generated
11350
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "1.0.24",
|
"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,32 +13,38 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.10",
|
||||||
"@types/node": "^12.7.2",
|
"@types/node": "^14.14.22",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartnetwork": "^1.1.6",
|
"@pushrocks/lik": "^4.0.20",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartnetwork": "^1.1.22",
|
||||||
"@pushrocks/smartrequest": "^1.1.23",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.51",
|
||||||
"@pushrocks/smartspawn": "^2.0.9",
|
"@pushrocks/smartspawn": "^2.0.9",
|
||||||
"@pushrocks/smartsystem": "^2.0.8",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@tsclass/tsclass": "^2.0.5",
|
"@pushrocks/smartsystem": "^2.0.9",
|
||||||
"@types/ws": "^6.0.2",
|
"@tsclass/tsclass": "^3.0.29",
|
||||||
"ws": "^7.1.2"
|
"@types/ws": "^7.4.0",
|
||||||
|
"ws": "^7.4.2"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts/**/*",
|
||||||
"assets/*",
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"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/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartproxy/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartproxy/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartproxy/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartproxy)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartproxy)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
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
|
## 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.
|
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)
|
||||||
|
27
test/cert.pem
Normal file
27
test/cert.pem
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEljCCAn4CCQDY+ZbC9FASVjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJE
|
||||||
|
RTAeFw0xOTA5MjAxNjAxNDRaFw0yMDA5MTkxNjAxNDRaMA0xCzAJBgNVBAYTAkRF
|
||||||
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA4thf9JEK/epoXt8hFr8t
|
||||||
|
pkRzmaEkgbSKoOga3uGXDLvdNf3BzSIxZ8pzRhZfUnutcmW1thdz3wre/pEJR7oN
|
||||||
|
QsfixbLL8/oS5QeXKiUGX0Ssfdg4W0TsoLcRva+1AZsf38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QGh/l2MrOjamcSo0+wYhOqlX3WNdaKNAzPqloBnF6w7eqLYde
|
||||||
|
h9He39ySmxjENwv3miOjEP1sBeMBSRfL/ckEonfK5uJgYA5nVMQ3ojUeDMZzLfFE
|
||||||
|
Ue2WHt+uPyYk7mMZfOrK2uHzI2/Coqj7lbfRodFwj+fCArYBck2NZannDPKA6X8V
|
||||||
|
TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
|
||||||
|
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
|
||||||
|
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||||
|
-----END CERTIFICATE-----
|
52
test/key.pem
Normal file
52
test/key.pem
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
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
|
||||||
|
2TkK01XDDJURK5Lhuvc7WrK2rSJ/fK+0GA==
|
||||||
|
-----END PRIVATE KEY-----
|
101
test/test.ts
101
test/test.ts
@ -3,20 +3,107 @@ import * as smartproxy from '../ts/index';
|
|||||||
|
|
||||||
let testProxy: smartproxy.SmartProxy;
|
let testProxy: smartproxy.SmartProxy;
|
||||||
|
|
||||||
if (process.env.CI) {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 () => {
|
||||||
await testProxy.start();
|
await testProxy.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should wait for 5 seconds', async tools => {
|
tap.test('should supply reverse proxy config', async () => {
|
||||||
await tools.delayFor(1000);
|
testProxy.updateReverseConfigs([
|
||||||
|
{
|
||||||
|
destinationIp: 'localhost',
|
||||||
|
destinationPort: '3000',
|
||||||
|
hostName: 'push.rocks',
|
||||||
|
privateKey: `-----BEGIN PRIVATE KEY-----
|
||||||
|
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe
|
||||||
|
3yEWvy2mRHOZoSSBtIqg6Bre4ZcMu901/cHNIjFnynNGFl9Se61yZbW2F3PfCt7+
|
||||||
|
kQlHug1Cx+LFssvz+hLlB5cqJQZfRKx92DhbROygtxG9r7UBmx/fwx+JQ+HOHX9R
|
||||||
|
b+szLBZqxrNDBFl2SRdviconYgVnHbaqcAPj/lK6D6x94qgUEX+vMjbIruuiCe3u
|
||||||
|
RbYse/quzAednVnY/+BuGVn8SEb2EVVFnBEsOxxYpy5ZzGR48O3YnWkM2oPpJhrp
|
||||||
|
mMYLcARMnDmIQDVstD1i+MM2lVhx/pm9xKKUgWNJC7lyz2xRscZ4pOtLkfN94leH
|
||||||
|
U98nIvxfQe7tQFKN9K52yjdtoT0UaIEUFbZyddkoNka1Xx6r+rE96046BLT2lVs0
|
||||||
|
/rnTxZUFH6vP3z9UNktmpxtnZSk67Pj6QAqZtgT0amXEpBlk7vBYSjHsyJ3+5R1y
|
||||||
|
oSjhAqeejq6M67NDOflrag5LSTkeTe4dqk0laVb1gjcse18AOlgf7pw5H79zclYH
|
||||||
|
NAnoAPua683MD2ZZd4eov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VuU3jpWZkBE2VhXpDXlyW8xR/y1ZOaZZ//XcZTrZf57pGKFp30H/PlDPH3C
|
||||||
|
YtjEuQNmPCgnfz8iXx+vDYx8hwLHNv+DoX2WYuThUnul/QGSKL3xh3qWd8rotnUB
|
||||||
|
c8bV4ymk35fVJu/+pTZpPnMkYrFReso/uNn07y1iga/9mwkUBNrT+fWE7RzjT7H8
|
||||||
|
ykMMOGCK6bc7joCvALZaUDne714hNW3s9a7L1clehUA8/xwplQKCAQEA6jx/CIQd
|
||||||
|
RVdJFihSSZbqdrOAblVdl+WkjhALWNRMoRCCRniNubbgxgKfQ0scKUeubYxScBVk
|
||||||
|
rlUMl6/2Gr9uzuSC0WPVAE6OLvLNcQafw1mQ1UTJiEzYvczJKwipzXcgGQWO9Q9a
|
||||||
|
T3ETh6Be62si2r6fH4agQzbp4HkTEoWgPu6MJpqqcLoc8laty0d1huqU9du1TRzT
|
||||||
|
3etjopWRd0I3ID+WkkGKjYWRQ1bkKjvkkj1v7bHenX17nfIp5WU1aXTMYUCMMszm
|
||||||
|
pgVBDeJGKpPpP3scl7go5Y4KC6H+IeYaeCEk3hWW4robpHBzupkgpRLzmBopjRlN
|
||||||
|
v3+HQ7OkviX88QKCAQEAg5IJdfKKfindzYieM3WwjW8VkH4LdVLQSW3WlCkMkVgC
|
||||||
|
ShjBQj3OeKeeik4ABRlYRW1AqZs+YSmrsUXqPfIeCqNCDoSwKk7ZKGSYr49uWbbc
|
||||||
|
fkM/buxUnXPAryjbVddos+ds7KtkZkjkMSby9iHjxA11GLnF737pK8Uh0Atx+y3O
|
||||||
|
p8Y3j9QVjZ3m7K3NuGjFCG75kE5x7PHCkl+Ea4zV4EFNWLS5/cD1Vz8pEiRHhlKn
|
||||||
|
aPHO8OcUoOELYVUBzk6EC0IiJxukXPoc+O5JDGn48cqgDFs7vApEqBqxKTYD2jeC
|
||||||
|
AR54wNuSBDLCIylTIn016oD37DpjeoVvYBADTu/HMQKCAQEA1rFuajrVrWnMpo98
|
||||||
|
pNC7xOLQM9DwwToOMtwH2np0ZiiAj+ENXgx+R1+95Gsiu79k5Cn6oZsqNhPkP+Bb
|
||||||
|
fba69M1EDnInmGloLyYDIbbFlsMwWhn7cn+lJYpfVJ9TK+0lMWoD1yAkUa4+DVDz
|
||||||
|
z2naf466wKWfnRvnEAVJcu+hqizxrqySzlH4GDNUhn7P/UJkGFkx+yUSGFUZdLsM
|
||||||
|
orfBWUCPXSzPttmXBJbO+Nr+rP+86KvgdI/AT0vYFNdINomEjxsfpaxjOAaW0wfz
|
||||||
|
8jCyWKoZ0gJNEeK32GO5UA7dcgBHD3vQWa3lijo8COsznboaJe7M6PQpa/2S2H3+
|
||||||
|
4P5msQKCAQEAx7NP3y+5ttfTd/eQ7/cg1/0y2WxvpOYNLt6MWz4rPWyD6QwidzTG
|
||||||
|
pjuQFQ5Ods+BwJ/Jbirb7l4GMAxfIbEPAkPTHpvswO0xcncSYxl0sSP/WIA6sbcM
|
||||||
|
dp7B/scdORC8Y6i8oPdCyxyCTd2SBrmGr2krAXmQquT72eusyP5E8HFhCy1iYt22
|
||||||
|
aL68dZLv9/sRAF08t9Wy+eYjD/hCj67t7uGCZQT8wJbKr8aJcjwVwJgghh+3EydK
|
||||||
|
h+7fBVO49PLL0NWy+8GT8y7a04calFfLvZEA2UMaunBis3dE1KMFfJL/0JO+sKnF
|
||||||
|
2TkK01XDDJURK5Lhuvc7WrK2rSJ/fK+0GA==
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
|
`,
|
||||||
|
publicKey: `-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEljCCAn4CCQDY+ZbC9FASVjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJE
|
||||||
|
RTAeFw0xOTA5MjAxNjAxNDRaFw0yMDA5MTkxNjAxNDRaMA0xCzAJBgNVBAYTAkRF
|
||||||
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA4thf9JEK/epoXt8hFr8t
|
||||||
|
pkR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OEGcOo7wJt6wrH/lko9
|
||||||
|
LxX96GC1JoN1Pfr2FoTKy1WHzrSfyGmDIUCrbaYQ58UuMOR+5eIPPdkf/030u5eX
|
||||||
|
xXhF2fBujD57E2zQGh/l2MrOjamcSo0+wYhOqlX3WNdaKNAzPqloBnF6w7eqLYde
|
||||||
|
h9He39ySmxjENwv3miOjEP1sBeMBSRfL/ckEonfK5uJgYA5nVMQ3ojUeDMZzLfFE
|
||||||
|
Ue2WHt+uPyYk7mMZfOrK2uHzI2/Coqj7lbfRodFwj+fCArYBck2NZannDPKA6X8V
|
||||||
|
TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
|
||||||
|
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
|
||||||
|
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should wait for 60 seconds', async (tools) => {
|
||||||
|
await tools.delayFor(10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should close the testproxy', async () => {
|
tap.test('should close the testproxy', async () => {
|
||||||
|
@ -3,83 +3,250 @@ 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>();
|
||||||
public async setPort(portArg: number) {
|
public defaultHeaders: {[key: string]: string} = {};
|
||||||
this.port = portArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts the proxyInstance
|
* starts the proxyInstance
|
||||||
*/
|
*/
|
||||||
public async start() {
|
public async start() {
|
||||||
this.httpsServer = plugins.https.createServer(async (req, res) => {
|
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-----
|
||||||
|
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
|
||||||
|
2TkK01XDDJURK5Lhuvc7WrK2rSJ/fK+0GA==
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
|
`,
|
||||||
|
cert: `-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEljCCAn4CCQDY+ZbC9FASVjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJE
|
||||||
|
RTAeFw0xOTA5MjAxNjAxNDRaFw0yMDA5MTkxNjAxNDRaMA0xCzAJBgNVBAYTAkRF
|
||||||
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA4th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NMy0F3NAZBkZ/+k21HZo6FmVi+q6OEGcOo7wJt6wrH/lko9
|
||||||
|
LxX96GC1JoN1Pfr2FoTKy1WHzrSfyGmDIUCrbaYQ58UuMOR+5eIPPdkf/030u5eX
|
||||||
|
xXhF2fBujD57E2zQGh/l2MrOjamcSo0+wYhOqlX3WNdaKNAzPqloBnF6w7eqLYde
|
||||||
|
h9He39ySmxjENwv3miOjEP1sBeMBSRfL/ckEonfK5uJgYA5nVMQ3ojUeDMZzLfFE
|
||||||
|
Ue2WHt+uPyYk7mMZfOrK2uHzI2/Coqj7lbfRodFwj+fCArYBck2NZannDPKA6X8V
|
||||||
|
TzJTbTCteOUUJTrcfZ0gGhGkF4nYLmX5OI+TPqrDJf0fZ+mzAEHzDDVXcBYpYRDr
|
||||||
|
r8d9QwrK+WaqVi2ofbMfMByVF72jgeJNa4nxwT9bVbu/Q1T2Lt+YPb4pQ7yCoUgS
|
||||||
|
JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
async (req, res) => {
|
||||||
|
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 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', () => {
|
||||||
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');
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
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.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);
|
||||||
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.listen(this.port); */
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
@ -87,6 +254,9 @@ export class ProxyWorker {
|
|||||||
this.httpsServer.close(() => {
|
this.httpsServer.close(() => {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
|
await this.socketMap.forEach(async (socket) => {
|
||||||
|
socket.destroy();
|
||||||
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +271,10 @@ const proxyWorkerCalls = {
|
|||||||
start: async () => {
|
start: async () => {
|
||||||
await proxyWorkerInstance.start();
|
await proxyWorkerInstance.start();
|
||||||
},
|
},
|
||||||
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {}
|
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
||||||
|
await proxyWorkerInstance.updateProxyConfigs(configArray);
|
||||||
|
},
|
||||||
|
addDefaultHeaders: async (headers: {[key: string]: string}) => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
|
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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!');
|
||||||
|
@ -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 };
|
||||||
|
@ -1,25 +1,79 @@
|
|||||||
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;
|
||||||
.createServer(from => {
|
let httpServer: plugins.http.Server;
|
||||||
const to = net.createConnection({
|
|
||||||
host: 'localhost',
|
|
||||||
port: 8001
|
|
||||||
});
|
|
||||||
from.pipe(to);
|
|
||||||
to.pipe(from);
|
|
||||||
})
|
|
||||||
.listen(8000);
|
|
||||||
|
|
||||||
const portProxyCalls = {
|
const portProxyCalls = {
|
||||||
|
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
|
||||||
|
.createServer((from) => {
|
||||||
|
const to = net.createConnection({
|
||||||
|
host: 'localhost',
|
||||||
|
port: 8001,
|
||||||
|
});
|
||||||
|
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(portArg);
|
||||||
|
console.log(`PortProxy -> OK: Now listening on port ${portArg}`);
|
||||||
|
},
|
||||||
stop: async () => {
|
stop: async () => {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
server.close(() => {
|
httpServer.close(() => {
|
||||||
|
netServer.close(() => {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TPortProxyCalls = typeof portProxyCalls;
|
export type TPortProxyCalls = typeof portProxyCalls;
|
||||||
|
Reference in New Issue
Block a user