fix(core): initial
This commit is contained in:
@ -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
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './vhostconfig';
|
9
ts/interfaces/vhostconfig.ts
Normal file
9
ts/interfaces/vhostconfig.ts
Normal 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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -8,3 +8,10 @@ export {
|
||||
smartproxy,
|
||||
smartnetwork
|
||||
}
|
||||
|
||||
// tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export {
|
||||
tsclass
|
||||
};
|
||||
|
Reference in New Issue
Block a user