Compare commits

...

6 Commits

Author SHA1 Message Date
3238ea5cfd 1.0.16 2019-08-21 23:55:46 +02:00
20dc9238e4 fix(core): update 2019-08-21 23:55:45 +02:00
2b9b7cf691 1.0.15 2019-08-21 23:54:56 +02:00
0b7f5c4701 fix(core): update 2019-08-21 23:54:55 +02:00
23fa6a6511 1.0.14 2019-08-21 23:41:06 +02:00
ff8e185ec3 fix(core): update 2019-08-21 23:41:06 +02:00
6 changed files with 139 additions and 50 deletions

31
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.13",
"version": "1.0.16",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -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

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.13",
"version": "1.0.16",
"private": false,
"description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js",
@ -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

@ -1,5 +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();
});
}
}

View File

@ -1,12 +1,7 @@
import * as plugins from './smartproxy.plugins';
import * as interfaces from './interfaces';
import { SmartproxyRouter } from './smartproxy.classes.router';
import { Socket } from 'net';
export class SmartProxy {
public httpsServer: plugins.https.Server | plugins.http.Server;
public router = new SmartproxyRouter();
public hostCandidates: interfaces.IHostConfig[] = [];
@ -15,42 +10,13 @@ export class SmartProxy {
this.hostCandidates.push(hostCandidate);
}
/**
* 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
}); */
}
this.httpsServer.on('upgrade', (req, socket: Socket) => {
})
this.httpsServer.listen(3000);
async start () {
}
public async update() {
await this.start();
async stop () {
}
}

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
};