feat(PortProxy): Enhance PortProxy to support domain-specific target IPs

This commit is contained in:
2025-02-21 19:34:11 +00:00
parent 9be9a426ad
commit 8e5bb12edb
4 changed files with 63 additions and 3 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartproxy',
version: '3.4.4',
version: '3.5.0',
description: 'a proxy for handling high workloads of proxying'
}

View File

@ -4,6 +4,7 @@ import * as plugins from './smartproxy.plugins.js';
export interface DomainConfig {
domain: string; // glob pattern for domain
allowedIPs: string[]; // glob patterns for IPs allowed to access this domain
targetIP?: string; // Optional target IP for this domain
}
export interface ProxySettings extends plugins.tls.TlsOptions {
@ -118,11 +119,15 @@ export class PortProxy {
return;
}
// Determine target host - use domain-specific targetIP if available
const domainConfig = serverName ? findMatchingDomain(serverName) : undefined;
const targetHost = domainConfig?.targetIP || this.settings.toHost!;
const to = plugins.net.createConnection({
host: this.settings.toHost!,
host: targetHost,
port: this.settings.toPort,
});
console.log(`Connection established: ${remoteIP} -> ${this.settings.toHost}:${this.settings.toPort}${serverName ? ` (SNI: ${serverName})` : ''}`);
console.log(`Connection established: ${remoteIP} -> ${targetHost}:${this.settings.toPort}${serverName ? ` (SNI: ${serverName})` : ''}`);
from.setTimeout(120000);
from.pipe(to);
to.pipe(from);