fix(core): update
This commit is contained in:
parent
c32a56d921
commit
ff8e185ec3
29
package-lock.json
generated
29
package-lock.json
generated
@ -318,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",
|
||||||
@ -393,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",
|
||||||
@ -411,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",
|
||||||
@ -459,6 +471,11 @@
|
|||||||
"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",
|
||||||
@ -1708,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",
|
||||||
|
@ -21,7 +21,11 @@
|
|||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartrequest": "^1.1.20"
|
"@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": [
|
"files": [
|
||||||
"ts/*",
|
"ts/*",
|
||||||
|
13
test/test.ts
13
test/test.ts
@ -1,9 +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 () => {
|
||||||
const testProxy = new smartproxy.SmartProxy();
|
testProxy = new smartproxy.SmartProxy();
|
||||||
// await testProxy.start();
|
});
|
||||||
|
|
||||||
|
tap.test('should start the testproxy', async () => {
|
||||||
|
await testProxy.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should close the testproxy', async () => {
|
||||||
|
await testProxy.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -21,10 +21,14 @@ export class SmartProxy {
|
|||||||
public async start() {
|
public async start() {
|
||||||
this.httpsServer = plugins.http.createServer(async (req, res) => {
|
this.httpsServer = plugins.http.createServer(async (req, res) => {
|
||||||
req.headers.host = this.router.routeReq(req);
|
req.headers.host = this.router.routeReq(req);
|
||||||
const response = await plugins.smartrequest.request(`https://${req.headers.host}${req.url}`, {
|
const response = await plugins.smartrequest.request(
|
||||||
method: req.method,
|
`https://${req.headers.host}${req.url}`,
|
||||||
headers: req.headers
|
{
|
||||||
}, true);
|
method: req.method,
|
||||||
|
headers: req.headers
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
res.statusCode = response.statusCode;
|
res.statusCode = response.statusCode;
|
||||||
for (const header of Object.keys(response.headers)) {
|
for (const header of Object.keys(response.headers)) {
|
||||||
res.setHeader(header, response.headers[header]);
|
res.setHeader(header, response.headers[header]);
|
||||||
@ -42,15 +46,44 @@ export class SmartProxy {
|
|||||||
key: hostCandidate.privateKey
|
key: hostCandidate.privateKey
|
||||||
}); */
|
}); */
|
||||||
}
|
}
|
||||||
this.httpsServer.on('upgrade', (req, socket: Socket) => {
|
|
||||||
|
|
||||||
})
|
// 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);
|
this.httpsServer.listen(3000);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update() {
|
public async update() {
|
||||||
await this.start();
|
await this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
|
this.httpsServer.close(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
// node native scope
|
// node native scope
|
||||||
import * as http from 'http';
|
import crypto from 'crypto';
|
||||||
import * as https from 'https';
|
import http from 'http';
|
||||||
|
import https from 'https';
|
||||||
|
|
||||||
export { http, https };
|
export { crypto, http, https };
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
smartrequest
|
smartrequest,
|
||||||
|
smartpromise
|
||||||
|
};
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import ws from 'ws';
|
||||||
|
|
||||||
|
export {
|
||||||
|
ws
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user