refactor: migrate coretraffic to current smartproxy
This commit is contained in:
@@ -9,13 +9,14 @@ export class CoretrafficTaskManager {
|
||||
/**
|
||||
* a task to run setup routing, runs buffered
|
||||
*/
|
||||
public setupRoutingTask: plugins.taskbuffer.Task<plugins.tsclass.network.IReverseProxyConfig[]>;
|
||||
public setupRoutingTask: plugins.taskbuffer.Task;
|
||||
|
||||
constructor(coretrafficRefArg: CoreTraffic) {
|
||||
this.coretrafficRef = coretrafficRefArg;
|
||||
this.taskmanager = new plugins.taskbuffer.TaskManager();
|
||||
|
||||
this.setupRoutingTask = new plugins.taskbuffer.Task({
|
||||
name: 'setupRouting',
|
||||
buffered: true,
|
||||
bufferMax: 2,
|
||||
taskFunction: async (reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
||||
@@ -24,11 +25,78 @@ export class CoretrafficTaskManager {
|
||||
logger.log('info', `routing setup task triggered`);
|
||||
logger.log('info', `Found ${reverseConfigs.length} host reverse configs!`);
|
||||
logger.log('info', `trying to deploy host candidates now`);
|
||||
await this.coretrafficRef.networkProxy.updateProxyConfigs(reverseConfigs);
|
||||
await this.coretrafficRef.smartProxy.updateRoutes(this.createRoutesFromReverseConfigs(reverseConfigs));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private createRoutesFromReverseConfigs(
|
||||
reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[]
|
||||
): plugins.smartproxy.IRouteConfig[] {
|
||||
const responseHeaders = this.coretrafficRef.getDefaultResponseHeaders();
|
||||
const routes: plugins.smartproxy.IRouteConfig[] = [
|
||||
{
|
||||
name: 'http-to-https-redirect',
|
||||
match: {
|
||||
ports: 7999,
|
||||
protocol: 'http',
|
||||
},
|
||||
action: {
|
||||
type: 'socket-handler',
|
||||
socketHandler: plugins.smartproxy.SocketHandlers.httpRedirect('https://{domain}{path}', 301),
|
||||
},
|
||||
headers: {
|
||||
response: responseHeaders,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
for (const reverseConfig of reverseConfigs) {
|
||||
routes.push({
|
||||
name: `https-${reverseConfig.hostName}`,
|
||||
match: {
|
||||
ports: 8000,
|
||||
domains: reverseConfig.hostName,
|
||||
protocol: 'http',
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
targets: reverseConfig.destinationIps.flatMap((destinationIp) =>
|
||||
reverseConfig.destinationPorts.map((destinationPort) => ({
|
||||
host: destinationIp,
|
||||
port: destinationPort,
|
||||
}))
|
||||
),
|
||||
tls: {
|
||||
mode: 'terminate',
|
||||
certificate: {
|
||||
key: reverseConfig.privateKey,
|
||||
cert: reverseConfig.publicKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
response: responseHeaders,
|
||||
},
|
||||
security: reverseConfig.authentication
|
||||
? {
|
||||
basicAuth: {
|
||||
enabled: true,
|
||||
users: [
|
||||
{
|
||||
username: reverseConfig.authentication.user,
|
||||
password: reverseConfig.authentication.pass,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
public async start() {}
|
||||
|
||||
public async stop() {}
|
||||
|
||||
Reference in New Issue
Block a user