fix(core): update
This commit is contained in:
parent
5eebc434bb
commit
8f4421fbc3
@ -3,7 +3,7 @@ import * as plugins from './smartproxy.plugins';
|
|||||||
import { SmartproxyRouter } from './smartproxy.classes.router';
|
import { SmartproxyRouter } from './smartproxy.classes.router';
|
||||||
|
|
||||||
export class ProxyWorker {
|
export class ProxyWorker {
|
||||||
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||||
public httpsServer: plugins.https.Server; // | plugins.http.Server;
|
public httpsServer: plugins.https.Server; // | plugins.http.Server;
|
||||||
public port = 8001;
|
public port = 8001;
|
||||||
public router = new SmartproxyRouter();
|
public router = new SmartproxyRouter();
|
||||||
@ -160,10 +160,10 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
console.log(`OK: now listening for new connections on port ${this.port}`);
|
console.log(`OK: now listening for new connections on port ${this.port}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateCandidates(arrayOfReverseCandidates: plugins.tsclass.IReverseProxyConfig[]) {
|
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.IReverseProxyConfig[]) {
|
||||||
this.hostCandidates = arrayOfReverseCandidates;
|
this.proxyConfigs = proxyConfigsArg;
|
||||||
this.router.setNewCandidates(arrayOfReverseCandidates);
|
this.router.setNewProxyConfigs(proxyConfigsArg);
|
||||||
for (const hostCandidate of this.hostCandidates) {
|
for (const hostCandidate of this.proxyConfigs) {
|
||||||
// console.log(hostCandidate);
|
// console.log(hostCandidate);
|
||||||
this.httpsServer.addContext(hostCandidate.hostName, {
|
this.httpsServer.addContext(hostCandidate.hostName, {
|
||||||
cert: hostCandidate.publicKey,
|
cert: hostCandidate.publicKey,
|
||||||
@ -194,7 +194,7 @@ const proxyWorkerCalls = {
|
|||||||
await proxyWorkerInstance.start();
|
await proxyWorkerInstance.start();
|
||||||
},
|
},
|
||||||
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
||||||
await proxyWorkerInstance.updateCandidates(configArray);
|
await proxyWorkerInstance.updateProxyConfigs(configArray);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,18 +1,22 @@
|
|||||||
import * as plugins from './smartproxy.plugins';
|
import * as plugins from './smartproxy.plugins';
|
||||||
|
|
||||||
export class SmartproxyRouter {
|
export class SmartproxyRouter {
|
||||||
public reverseCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
public reverseProxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets a new set of reverse configs to be routed to
|
* sets a new set of reverse configs to be routed to
|
||||||
* @param reverseCandidatesArg
|
* @param reverseCandidatesArg
|
||||||
*/
|
*/
|
||||||
public setNewCandidates(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
public setNewProxyConfigs(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
||||||
this.reverseCandidates = reverseCandidatesArg;
|
this.reverseProxyConfigs = reverseCandidatesArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* routes a request
|
||||||
|
*/
|
||||||
public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig {
|
public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig {
|
||||||
const originalHost = req.headers.host;
|
const originalHost = req.headers.host;
|
||||||
const correspodingReverseProxyConfig = this.reverseCandidates.find(reverseConfig => {
|
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => {
|
||||||
return reverseConfig.hostName === originalHost;
|
return reverseConfig.hostName === originalHost;
|
||||||
});
|
});
|
||||||
return correspodingReverseProxyConfig;
|
return correspodingReverseProxyConfig;
|
||||||
|
Loading…
Reference in New Issue
Block a user