fix(core): initial

This commit is contained in:
Philipp Kunz 2020-02-07 20:00:01 +00:00
parent 029daf272f
commit 9abd746384
9 changed files with 136 additions and 33 deletions

47
package-lock.json generated
View File

@ -314,19 +314,20 @@
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
},
"@pushrocks/smartproxy": {
"version": "1.0.32",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartproxy/-/smartproxy-1.0.32.tgz",
"integrity": "sha512-+JTZ0gwyPpI0oUkl3DHkZy+A6LyDLbOzKj9F+uwZljfNerIwxGhg4d3r9DvBL1h//zyC5PFvRC0JSvHQ7bxaTA==",
"version": "2.0.0",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartproxy/-/smartproxy-2.0.0.tgz",
"integrity": "sha512-r+N1S2VdOr8lYYvSUSQHDllxFKcWJ3c+CXfaFL6Hfm2HL/Ps9XdUMVn6EJEgVEKNX8jAWIW/72yoaDCyOCtZQA==",
"requires": {
"@pushrocks/lik": "^3.0.11",
"@pushrocks/smartnetwork": "^1.1.14",
"@pushrocks/smartpromise": "^3.0.5",
"@pushrocks/smartrequest": "^1.1.35",
"@pushrocks/lik": "^3.0.16",
"@pushrocks/smartnetwork": "^1.1.18",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47",
"@pushrocks/smartspawn": "^2.0.9",
"@pushrocks/smartstring": "^3.0.18",
"@pushrocks/smartsystem": "^2.0.9",
"@tsclass/tsclass": "^2.0.6",
"@types/ws": "^6.0.3",
"ws": "^7.1.2"
"@tsclass/tsclass": "^3.0.3",
"@types/ws": "^7.2.1",
"ws": "^7.2.1"
}
},
"@pushrocks/smartrequest": {
@ -447,9 +448,9 @@
}
},
"@tsclass/tsclass": {
"version": "2.0.13",
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-2.0.13.tgz",
"integrity": "sha512-ZhN3vLAahP4DOayACh/bskG4SpeqNpR4oH9776hZvz6GoFj7KQinzf03gzC5o2o6tnmOusQ1FYu1NGYmy6Rvdg==",
"version": "3.0.3",
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-3.0.3.tgz",
"integrity": "sha512-BsPx1VVyXPMMqfERTMoseRQof8kWZZqeHl74un8Ba0aBxZx4DeEgi6OBR1XroWb4Znv+yOP+QQKOwHAffkKvMQ==",
"requires": {
"@pushrocks/tapbundle": "^3.0.13"
}
@ -587,9 +588,9 @@
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
},
"@types/node": {
"version": "10.17.14",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-10.17.14.tgz",
"integrity": "sha512-G0UmX5uKEmW+ZAhmZ6PLTQ5eu/VPaT+d/tdLd5IFsKRPcbe6lPxocBtcYBFSaLaCW8O60AX90e91Nsp8lVHCNw=="
"version": "13.7.0",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-13.7.0.tgz",
"integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
},
"@types/portscanner": {
"version": "2.1.0",
@ -643,9 +644,9 @@
"dev": true
},
"@types/ws": {
"version": "6.0.4",
"resolved": "https://verdaccio.lossless.one/@types%2fws/-/ws-6.0.4.tgz",
"integrity": "sha512-PpPrX7SZW9re6+Ha8ojZG4Se8AZXgf0GK6zmfqEuCsY49LFDNXO3SByp44X3dFEqtB73lkCDAdUazhAjVPiNwg==",
"version": "7.2.1",
"resolved": "https://verdaccio.lossless.one/@types%2fws/-/ws-7.2.1.tgz",
"integrity": "sha512-UEmRNbXFGvfs/sLncf01GuVv6U1mZP3Df0iXWx4kUlikJxbFyFADp95mDn1XDTE2mXpzzoHcKlfFcbytLq4vaA==",
"requires": {
"@types/node": "*"
}
@ -3090,9 +3091,9 @@
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
},
"tslint": {
"version": "5.20.1",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.1.tgz",
"integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==",
"version": "6.0.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-6.0.0.tgz",
"integrity": "sha512-9nLya8GBtlFmmFMW7oXXwoXS1NkrccqTqAtwXzdPV9e2mqSEvCki6iHL/Fbzi5oqbugshzgGPk7KBb2qNP1DSA==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
@ -3106,7 +3107,7 @@
"mkdirp": "^0.5.1",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tslib": "^1.10.0",
"tsutils": "^2.29.0"
}
},

View File

@ -16,14 +16,15 @@
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.11.7",
"tslint": "^5.11.0",
"@types/node": "^13.7.0",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartexpress": "^3.0.57",
"@pushrocks/smartnetwork": "^1.1.18",
"@pushrocks/smartproxy": "^1.0.32"
"@pushrocks/smartproxy": "^2.0.0",
"@tsclass/tsclass": "^3.0.3"
},
"files": [
"ts/**/*",

View File

@ -1,8 +1,33 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartvhost from '../ts/index';
import { SmartVHost } from '../ts/index';
tap.test('first test', async () => {
console.log(smartvhost.standardExport);
import * as path from 'path';
let testSmartVHost: smartvhost.SmartVHost;
tap.test('should create a valid instance of smartvhost', async () => {
testSmartVHost = new smartvhost.SmartVHost();
expect(testSmartVHost).to.be.instanceOf(smartvhost.SmartVHost);
});
tap.test('should start smartvhost', async () => {
await testSmartVHost.start();
});
tap.test('should accept a config array', async () => {
testSmartVHost.setVHostConfigs([{
hostName: 'example.com',
privateKey: '',
publicKey: '',
type: 'folder',
target: path.join(__dirname, 'testservedir')
}]);
});
tap.test('should stop smartvhost', async () => {
await testSmartVHost.stop();
});
tap.start();

View File

@ -0,0 +1 @@
# Hello

View File

@ -1,3 +1 @@
import * as plugins from './smartvhost.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export * from './smartvhost.classes.smartvhost';

1
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './vhostconfig';

View File

@ -0,0 +1,9 @@
export type TVHostConfigType = 'folder' | 'ipAndPort' | 'localPort' | 'domain';
export interface IVHostConfig {
hostName: string;
type: TVHostConfigType;
target: string;
privateKey: string;
publicKey: string;
}

View File

@ -1,13 +1,73 @@
import * as plugins from './smartvhost.plugins';
import * as interfaces from './interfaces';
export class SmartVHost {
public smartproxy = new plugins.smartproxy.SmartProxy();
public currentConfig: interfaces.IVHostConfig[];
public smartproxy: plugins.smartproxy.SmartProxy;
public smartexpress: plugins.smartexpress.Server;
constructor() {
this.smartproxy = new plugins.smartproxy.SmartProxy({
port: 3000
});
this.smartexpress = new plugins.smartexpress.Server({
cors: true,
forceSsl: false,
port: 3001,
robots: 'standard'
});
}
public async start() {
await
await this.smartproxy.start();
await this.smartexpress.start();
}
public async stop() {
await this.smartproxy.stop();
await this.smartexpress.stop();
}
public setVHostConfigs(configArray: interfaces.IVHostConfig[]) {
this.currentConfig = configArray;
// lets route the traffic using smartproxy
const reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
for (const vHostConfig of this.currentConfig) {
switch(vHostConfig.type) {
case 'folder':
reverseConfigs.push({
destinationIp: '0.0.0.0',
destinationPort: '3001',
hostName: vHostConfig.hostName,
privateKey: vHostConfig.privateKey,
publicKey: vHostConfig.publicKey,
});
break;
case 'ipAndPort':
reverseConfigs.push({
destinationIp: vHostConfig.target.split(':')[0],
destinationPort: vHostConfig.target.split(':')[1],
hostName: vHostConfig.hostName,
privateKey: vHostConfig.privateKey,
publicKey: vHostConfig.publicKey
});
break;
case 'localPort':
reverseConfigs.push({
destinationIp: '0.0.0.0',
destinationPort: vHostConfig.target,
hostName: vHostConfig.hostName,
privateKey: vHostConfig.privateKey,
publicKey: vHostConfig.publicKey,
});
break;
case 'domain':
break;
default:
throw new Error(`unknown config type ${vHostConfig.type}`);
}
}
this.smartproxy.updateReverseConfigs(reverseConfigs);
}
}

View File

@ -8,3 +8,10 @@ export {
smartproxy,
smartnetwork
}
// tsclass scope
import * as tsclass from '@tsclass/tsclass';
export {
tsclass
};