feat(NetworkProxy): Add support for array-based destinations and integration with PortProxy
- Update NetworkProxy to support new IReverseProxyConfig interface with destinationIps[] and destinationPorts[] - Add load balancing with round-robin selection of destination endpoints - Create automatic conversion of PortProxy domain configs to NetworkProxy configs - Implement backward compatibility to ensure tests continue to work 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -429,7 +429,7 @@ export class PortProxy {
|
||||
/**
|
||||
* Initialize NetworkProxy instance
|
||||
*/
|
||||
private initializeNetworkProxy(): void {
|
||||
private async initializeNetworkProxy(): Promise<void> {
|
||||
if (!this.networkProxy) {
|
||||
this.networkProxy = new NetworkProxy({
|
||||
port: this.settings.networkProxyPort!,
|
||||
@@ -438,6 +438,59 @@ export class PortProxy {
|
||||
});
|
||||
|
||||
console.log(`Initialized NetworkProxy on port ${this.settings.networkProxyPort}`);
|
||||
|
||||
// Convert and apply domain configurations to NetworkProxy
|
||||
await this.syncDomainConfigsToNetworkProxy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the domain configurations for the proxy
|
||||
* @param newDomainConfigs The new domain configurations
|
||||
*/
|
||||
public async updateDomainConfigs(newDomainConfigs: IDomainConfig[]): Promise<void> {
|
||||
console.log(`Updating domain configurations (${newDomainConfigs.length} configs)`);
|
||||
this.settings.domainConfigs = newDomainConfigs;
|
||||
|
||||
// If NetworkProxy is initialized, resync the configurations
|
||||
if (this.networkProxy) {
|
||||
await this.syncDomainConfigsToNetworkProxy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes PortProxy domain configurations to NetworkProxy
|
||||
* This allows domains configured in PortProxy to be used by NetworkProxy
|
||||
*/
|
||||
private async syncDomainConfigsToNetworkProxy(): Promise<void> {
|
||||
if (!this.networkProxy) {
|
||||
console.log('Cannot sync configurations - NetworkProxy not initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Get SSL certificates from assets
|
||||
// Import fs directly since it's not in plugins
|
||||
const fs = await import('fs');
|
||||
const certPair = {
|
||||
key: fs.readFileSync('assets/certs/key.pem', 'utf8'),
|
||||
cert: fs.readFileSync('assets/certs/cert.pem', 'utf8')
|
||||
};
|
||||
|
||||
// Convert domain configs to NetworkProxy configs
|
||||
const proxyConfigs = this.networkProxy.convertPortProxyConfigs(
|
||||
this.settings.domainConfigs,
|
||||
certPair
|
||||
);
|
||||
|
||||
// Update NetworkProxy with the converted configs
|
||||
this.networkProxy.updateProxyConfigs(proxyConfigs).then(() => {
|
||||
console.log(`Successfully synchronized ${proxyConfigs.length} domain configurations to NetworkProxy`);
|
||||
}).catch(err => {
|
||||
console.log(`Error synchronizing configurations: ${err.message}`);
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(`Failed to sync configurations: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1278,6 +1331,11 @@ export class PortProxy {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize NetworkProxy if needed (useNetworkProxy is set but networkProxy isn't initialized)
|
||||
if (this.settings.useNetworkProxy && this.settings.useNetworkProxy.length > 0 && !this.networkProxy) {
|
||||
await this.initializeNetworkProxy();
|
||||
}
|
||||
|
||||
// Start NetworkProxy if configured
|
||||
if (this.networkProxy) {
|
||||
await this.networkProxy.start();
|
||||
|
Reference in New Issue
Block a user