Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b9b7cf691 | |||
0b7f5c4701 | |||
23fa6a6511 | |||
ff8e185ec3 | |||
c32a56d921 | |||
69233e8a3b | |||
23e6977d81 | |||
9f57b3b638 | |||
5df0a53efe | |||
6d1a781b9a | |||
81c9f3b72e | |||
c8ac0498c8 | |||
ee0900f3c0 | |||
7c46d16686 | |||
10cd3b3528 | |||
0e6c09aba5 | |||
2f4916f552 | |||
29bddf198f | |||
a5ecf0d9c1 | |||
1ccd53ce69 | |||
1264542410 | |||
ba55019846 | |||
6f967553d6 | |||
64df05a868 | |||
0a8ae81fd0 |
60
package-lock.json
generated
60
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "1.0.2",
|
"version": "1.0.15",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -247,14 +247,12 @@
|
|||||||
"@pushrocks/smartpromise": {
|
"@pushrocks/smartpromise": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
||||||
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ==",
|
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
"version": "1.1.19",
|
"version": "1.1.20",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.19.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.20.tgz",
|
||||||
"integrity": "sha512-puCBwk85JSOFCUU40EFxTk8yATCLEH90iaDycoWaR0ykOq1nSIWviyi49t4UUYM7lAjmTmMeTT+qOVF+508U2Q==",
|
"integrity": "sha512-3qOrxZT9+Fhr4GD/dFH+xDHYuSUTStbJl6/jNyh6W0d1L64zH2wfuG8MwlHc3CUHFXPaGauwK+4LQ91JEUx8TQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"@types/form-data": "^2.2.1",
|
"@types/form-data": "^2.2.1",
|
||||||
@ -320,6 +318,11 @@
|
|||||||
"smartchai": "^2.0.1"
|
"smartchai": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@tsclass/tsclass": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-13bn6eLaNN2gM5+ycZjulacEzpruOVOCcEMn1+2CZ8UAZf6yhghq+hXEUxqmuf1ZVR1CF+k9HsArxFBSh1cnUQ=="
|
||||||
|
},
|
||||||
"@types/chai": {
|
"@types/chai": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.0.tgz",
|
||||||
@ -367,7 +370,6 @@
|
|||||||
"version": "2.5.0",
|
"version": "2.5.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fform-data/-/form-data-2.5.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fform-data/-/form-data-2.5.0.tgz",
|
||||||
"integrity": "sha512-23/wYiuckYYtFpL+4RPWiWmRQH2BjFuqCUi2+N3amB1a1Drv+i/byTrGvlLwRVLFNAZbwpbQ7JvTK+VCAPMbcg==",
|
"integrity": "sha512-23/wYiuckYYtFpL+4RPWiWmRQH2BjFuqCUi2+N3amB1a1Drv+i/byTrGvlLwRVLFNAZbwpbQ7JvTK+VCAPMbcg==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"form-data": "*"
|
"form-data": "*"
|
||||||
}
|
}
|
||||||
@ -396,8 +398,7 @@
|
|||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.7.2",
|
"version": "12.7.2",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.2.tgz",
|
||||||
"integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==",
|
"integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/vinyl": {
|
"@types/vinyl": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
@ -414,6 +415,14 @@
|
|||||||
"integrity": "sha512-ZrJDWpvg75LTGX4XwuneY9s6bF3OeZcGTpoGh3zDV9ytzcHMFsRrMIaLBRJZQMBoGyKs6unBQfVdrLZiYfb1zQ==",
|
"integrity": "sha512-ZrJDWpvg75LTGX4XwuneY9s6bF3OeZcGTpoGh3zDV9ytzcHMFsRrMIaLBRJZQMBoGyKs6unBQfVdrLZiYfb1zQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/ws": {
|
||||||
|
"version": "6.0.2",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@types%2fws/-/ws-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-22XiR1ox9LftTaAtn/c5JCninwc7moaqbkJfaDUb7PkaUitcf5vbTZHdq9dxSMviCm9C3W85rzB8e6yNR70apQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/yargs": {
|
"@types/yargs": {
|
||||||
"version": "12.0.12",
|
"version": "12.0.12",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fyargs/-/yargs-12.0.12.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fyargs/-/yargs-12.0.12.tgz",
|
||||||
@ -462,11 +471,15 @@
|
|||||||
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
|
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"async-limiter": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/async-limiter/-/async-limiter-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
|
||||||
|
},
|
||||||
"asynckit": {
|
"asynckit": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/asynckit/-/asynckit-0.4.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
|
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
@ -637,7 +650,6 @@
|
|||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://verdaccio.lossless.one/combined-stream/-/combined-stream-1.0.8.tgz",
|
"resolved": "https://verdaccio.lossless.one/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"delayed-stream": "~1.0.0"
|
"delayed-stream": "~1.0.0"
|
||||||
}
|
}
|
||||||
@ -717,8 +729,7 @@
|
|||||||
"delayed-stream": {
|
"delayed-stream": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"diff": {
|
"diff": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
@ -811,7 +822,6 @@
|
|||||||
"version": "2.5.0",
|
"version": "2.5.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/form-data/-/form-data-2.5.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/form-data/-/form-data-2.5.0.tgz",
|
||||||
"integrity": "sha512-WXieX3G/8side6VIqx44ablyULoGruSde5PNTxoUyo5CeyAMX6nVWUd0rgist/EuX655cjhUhTo1Fo3tRYqbcA==",
|
"integrity": "sha512-WXieX3G/8side6VIqx44ablyULoGruSde5PNTxoUyo5CeyAMX6nVWUd0rgist/EuX655cjhUhTo1Fo3tRYqbcA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"asynckit": "^0.4.0",
|
"asynckit": "^0.4.0",
|
||||||
"combined-stream": "^1.0.6",
|
"combined-stream": "^1.0.6",
|
||||||
@ -1047,14 +1057,12 @@
|
|||||||
"mime-db": {
|
"mime-db": {
|
||||||
"version": "1.40.0",
|
"version": "1.40.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.40.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.40.0.tgz",
|
||||||
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==",
|
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"mime-types": {
|
"mime-types": {
|
||||||
"version": "2.1.24",
|
"version": "2.1.24",
|
||||||
"resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.24.tgz",
|
"resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.24.tgz",
|
||||||
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
|
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"mime-db": "1.40.0"
|
"mime-db": "1.40.0"
|
||||||
}
|
}
|
||||||
@ -1546,9 +1554,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"tslint": {
|
"tslint": {
|
||||||
"version": "5.18.0",
|
"version": "5.19.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.18.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.19.0.tgz",
|
||||||
"integrity": "sha512-Q3kXkuDEijQ37nXZZLKErssQVnwCV/+23gFEMROi8IlbaBG6tXqLPQJ5Wjcyt/yHPKBC+hD5SzuGaMora+ZS6w==",
|
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@babel/code-frame": "^7.0.0",
|
"@babel/code-frame": "^7.0.0",
|
||||||
@ -1717,6 +1725,14 @@
|
|||||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"ws": {
|
||||||
|
"version": "7.1.2",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/ws/-/ws-7.1.2.tgz",
|
||||||
|
"integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==",
|
||||||
|
"requires": {
|
||||||
|
"async-limiter": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/y18n/-/y18n-4.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/y18n/-/y18n-4.0.0.tgz",
|
||||||
|
23
package.json
23
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "1.0.2",
|
"version": "1.0.15",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a proxy for handling high workloads of proxying",
|
"description": "a proxy for handling high workloads of proxying",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -17,8 +17,25 @@
|
|||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.15",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"@types/node": "^12.7.2",
|
"@types/node": "^12.7.2",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.19.0",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {
|
||||||
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.20",
|
||||||
|
"@tsclass/tsclass": "^2.0.3",
|
||||||
|
"@types/ws": "^6.0.2",
|
||||||
|
"ws": "^7.1.2"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
26
readme.md
Normal file
26
readme.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# @pushrocks/smartproxy
|
||||||
|
a proxy for handling high workloads of proxying
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartproxy)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartproxy)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartproxy)
|
||||||
|
* [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/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
18
test/test.ts
18
test/test.ts
@ -1,8 +1,18 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartproxy from '../ts/index'
|
import * as smartproxy from '../ts/index';
|
||||||
|
|
||||||
|
let testProxy: smartproxy.SmartProxy;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
console.log(smartproxy.standardExport)
|
testProxy = new smartproxy.SmartProxy();
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.test('should start the testproxy', async () => {
|
||||||
|
await testProxy.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should close the testproxy', async () => {
|
||||||
|
await testProxy.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
@ -1,3 +1 @@
|
|||||||
import * as plugins from './smartproxy.plugins';
|
export * from './smartproxy.classes.smartproxy';
|
||||||
|
|
||||||
export let standardExport = 'Hi there! :) This is an exported string';
|
|
||||||
|
7
ts/interfaces/index.ts
Normal file
7
ts/interfaces/index.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface IHostConfig {
|
||||||
|
hostName: string;
|
||||||
|
destinationIp: string;
|
||||||
|
destinationPort: number;
|
||||||
|
privateKey: string;
|
||||||
|
publicKey: string;
|
||||||
|
}
|
80
ts/smartproxy.classes.proxyworker.ts
Normal file
80
ts/smartproxy.classes.proxyworker.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
import * as plugins from './smartproxy.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
import { SmartproxyRouter } from './smartproxy.classes.router';
|
||||||
|
|
||||||
|
export class ProxyWorker {
|
||||||
|
public httpsServer: plugins.https.Server | plugins.http.Server;
|
||||||
|
public router = new SmartproxyRouter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the proxyInstance
|
||||||
|
*/
|
||||||
|
public async start() {
|
||||||
|
this.httpsServer = plugins.http.createServer(async (req, res) => {
|
||||||
|
req.headers.host = this.router.routeReq(req);
|
||||||
|
const response = await plugins.smartrequest.request(
|
||||||
|
`https://${req.headers.host}${req.url}`,
|
||||||
|
{
|
||||||
|
method: req.method,
|
||||||
|
headers: req.headers
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
res.statusCode = response.statusCode;
|
||||||
|
for (const header of Object.keys(response.headers)) {
|
||||||
|
res.setHeader(header, response.headers[header]);
|
||||||
|
}
|
||||||
|
response.on('data', data => {
|
||||||
|
res.write(data);
|
||||||
|
});
|
||||||
|
response.on('end', () => {
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
for (const hostCandidate of this.hostCandidates) {
|
||||||
|
/* this.httpsServer.addContext(hostCandidate.hostName, {
|
||||||
|
cert: hostCandidate.publicKey,
|
||||||
|
key: hostCandidate.privateKey
|
||||||
|
}); */
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable websockets
|
||||||
|
const wss = new plugins.ws.Server({ server: this.httpsServer });
|
||||||
|
wss.on('connection', function connection(ws) {
|
||||||
|
const wscConnected = plugins.smartpromise.defer();
|
||||||
|
const wsc = new plugins.ws(`${ws.url}`);
|
||||||
|
wsc.on('open', () => {
|
||||||
|
wscConnected.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.on('message', async (message) => {
|
||||||
|
await wscConnected.promise;
|
||||||
|
wsc.emit('message', message);
|
||||||
|
});
|
||||||
|
wsc.on('message', (message) => {
|
||||||
|
ws.emit('message', message);
|
||||||
|
});
|
||||||
|
|
||||||
|
// handle closing
|
||||||
|
ws.on('close', (message) => {
|
||||||
|
wsc.close();
|
||||||
|
});
|
||||||
|
wsc.on('close', (message) => {
|
||||||
|
ws.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.httpsServer.listen(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update() {
|
||||||
|
await this.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
|
this.httpsServer.close(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
8
ts/smartproxy.classes.router.ts
Normal file
8
ts/smartproxy.classes.router.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import * as plugins from './smartproxy.plugins';
|
||||||
|
|
||||||
|
export class SmartproxyRouter {
|
||||||
|
|
||||||
|
public routeReq(req: plugins.http.IncomingMessage) {
|
||||||
|
return 'lossless.gmbh';
|
||||||
|
}
|
||||||
|
}
|
22
ts/smartproxy.classes.smartproxy.ts
Normal file
22
ts/smartproxy.classes.smartproxy.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import * as plugins from './smartproxy.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
export class SmartProxy {
|
||||||
|
|
||||||
|
public hostCandidates: interfaces.IHostConfig[] = [];
|
||||||
|
|
||||||
|
public addHostCandidate(hostCandidate: interfaces.IHostConfig) {
|
||||||
|
// TODO search for old hostCandidates with that target
|
||||||
|
this.hostCandidates.push(hostCandidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
async start () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async stop () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,22 @@
|
|||||||
const removeme = {};
|
// node native scope
|
||||||
|
import crypto from 'crypto';
|
||||||
|
import http from 'http';
|
||||||
|
import https from 'https';
|
||||||
|
|
||||||
|
export { crypto, http, https };
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
removeme
|
smartrequest,
|
||||||
}
|
smartpromise
|
||||||
|
};
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import ws from 'ws';
|
||||||
|
|
||||||
|
export {
|
||||||
|
ws
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user