fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-21 23:41:06 +02:00
parent c32a56d921
commit ff8e185ec3
5 changed files with 99 additions and 18 deletions

29
package-lock.json generated
View File

@ -318,6 +318,11 @@
"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": {
"version": "4.2.0",
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.0.tgz",
@ -393,8 +398,7 @@
"@types/node": {
"version": "12.7.2",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.2.tgz",
"integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==",
"dev": true
"integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg=="
},
"@types/vinyl": {
"version": "2.0.3",
@ -411,6 +415,14 @@
"integrity": "sha512-ZrJDWpvg75LTGX4XwuneY9s6bF3OeZcGTpoGh3zDV9ytzcHMFsRrMIaLBRJZQMBoGyKs6unBQfVdrLZiYfb1zQ==",
"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": {
"version": "12.0.12",
"resolved": "https://verdaccio.lossless.one/@types%2fyargs/-/yargs-12.0.12.tgz",
@ -459,6 +471,11 @@
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
"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": {
"version": "0.4.0",
"resolved": "https://verdaccio.lossless.one/asynckit/-/asynckit-0.4.0.tgz",
@ -1708,6 +1725,14 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"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": {
"version": "4.0.0",
"resolved": "https://verdaccio.lossless.one/y18n/-/y18n-4.0.0.tgz",

View File

@ -21,7 +21,11 @@
"tslint-config-prettier": "^1.15.0"
},
"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": [
"ts/*",

View File

@ -1,9 +1,18 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartproxy from '../ts/index';
let testProxy: smartproxy.SmartProxy;
tap.test('first test', async () => {
const testProxy = new smartproxy.SmartProxy();
// await testProxy.start();
testProxy = new smartproxy.SmartProxy();
});
tap.test('should start the testproxy', async () => {
await testProxy.start();
});
tap.test('should close the testproxy', async () => {
await testProxy.stop();
});
tap.start();

View File

@ -21,10 +21,14 @@ export class SmartProxy {
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);
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]);
@ -42,15 +46,44 @@ export class SmartProxy {
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);
}
public async update() {
await this.start();
}
public async stop() {
const done = plugins.smartpromise.defer();
this.httpsServer.close(() => {
done.resolve();
});
}
}

View File

@ -1,12 +1,22 @@
// node native scope
import * as http from 'http';
import * as https from 'https';
import crypto from 'crypto';
import http from 'http';
import https from 'https';
export { http, https };
export { crypto, http, https };
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export {
smartrequest
smartrequest,
smartpromise
};
// third party scope
import ws from 'ws';
export {
ws
};