BREAKING CHANGE(smartproxy/configuration): Migrate SmartProxy to a fully unified route‐based configuration by removing legacy domain-based settings and conversion code. CertProvisioner, NetworkProxyBridge, and RouteManager now use IRouteConfig exclusively, and related legacy interfaces and files have been removed.
This commit is contained in:
@ -377,10 +377,7 @@ export class NetworkProxyBridge {
|
||||
publicKey: certCert,
|
||||
destinationIps: targetHosts,
|
||||
destinationPorts: [targetPort],
|
||||
// Use backendProtocol for TLS re-encryption:
|
||||
backendProtocol: route.action.tls.mode === 'terminate-and-reencrypt' ? 'http2' : 'http1',
|
||||
// Add rewriteHostHeader for host header handling:
|
||||
rewriteHostHeader: route.action.advanced?.headers ? true : false
|
||||
// Headers handling happens in the request handler level
|
||||
};
|
||||
|
||||
configs.push(config);
|
||||
|
@ -303,135 +303,9 @@ export class RouteManager extends plugins.EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a domain config to routes
|
||||
* (For backward compatibility with code that still uses domainConfigs)
|
||||
* Domain-based configuration methods have been removed
|
||||
* as part of the migration to pure route-based configuration
|
||||
*/
|
||||
public domainConfigToRoutes(domainConfig: IDomainConfig): IRouteConfig[] {
|
||||
const routes: IRouteConfig[] = [];
|
||||
const { domains, forwarding } = domainConfig;
|
||||
|
||||
// Determine the action based on forwarding type
|
||||
let action: IRouteAction = {
|
||||
type: 'forward',
|
||||
target: {
|
||||
host: forwarding.target.host,
|
||||
port: forwarding.target.port
|
||||
}
|
||||
};
|
||||
|
||||
// Set TLS mode based on forwarding type
|
||||
switch (forwarding.type) {
|
||||
case 'http-only':
|
||||
// No TLS settings needed
|
||||
break;
|
||||
case 'https-passthrough':
|
||||
action.tls = { mode: 'passthrough' };
|
||||
break;
|
||||
case 'https-terminate-to-http':
|
||||
action.tls = {
|
||||
mode: 'terminate',
|
||||
certificate: forwarding.https?.customCert ? {
|
||||
key: forwarding.https.customCert.key,
|
||||
cert: forwarding.https.customCert.cert
|
||||
} : 'auto'
|
||||
};
|
||||
break;
|
||||
case 'https-terminate-to-https':
|
||||
action.tls = {
|
||||
mode: 'terminate-and-reencrypt',
|
||||
certificate: forwarding.https?.customCert ? {
|
||||
key: forwarding.https.customCert.key,
|
||||
cert: forwarding.https.customCert.cert
|
||||
} : 'auto'
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
// Add security settings if present
|
||||
if (forwarding.security) {
|
||||
action.security = {
|
||||
allowedIps: forwarding.security.allowedIps,
|
||||
blockedIps: forwarding.security.blockedIps,
|
||||
maxConnections: forwarding.security.maxConnections
|
||||
};
|
||||
}
|
||||
|
||||
// Add advanced settings if present
|
||||
if (forwarding.advanced) {
|
||||
action.advanced = {
|
||||
timeout: forwarding.advanced.timeout,
|
||||
headers: forwarding.advanced.headers,
|
||||
keepAlive: forwarding.advanced.keepAlive
|
||||
};
|
||||
}
|
||||
|
||||
// Determine which port to use based on forwarding type
|
||||
const defaultPort = forwarding.type.startsWith('https') ? 443 : 80;
|
||||
|
||||
// Add the main route
|
||||
routes.push({
|
||||
match: {
|
||||
ports: defaultPort,
|
||||
domains
|
||||
},
|
||||
action,
|
||||
name: `Route for ${domains.join(', ')}`
|
||||
});
|
||||
|
||||
// Add HTTP redirect if needed
|
||||
if (forwarding.http?.redirectToHttps) {
|
||||
routes.push({
|
||||
match: {
|
||||
ports: 80,
|
||||
domains
|
||||
},
|
||||
action: {
|
||||
type: 'redirect',
|
||||
redirect: {
|
||||
to: 'https://{domain}{path}',
|
||||
status: 301
|
||||
}
|
||||
},
|
||||
name: `HTTP Redirect for ${domains.join(', ')}`,
|
||||
priority: 100 // Higher priority for redirects
|
||||
});
|
||||
}
|
||||
|
||||
// Add port ranges if specified
|
||||
if (forwarding.advanced?.portRanges) {
|
||||
for (const range of forwarding.advanced.portRanges) {
|
||||
routes.push({
|
||||
match: {
|
||||
ports: [{ from: range.from, to: range.to }],
|
||||
domains
|
||||
},
|
||||
action,
|
||||
name: `Port Range ${range.from}-${range.to} for ${domains.join(', ')}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update routes based on domain configs
|
||||
* (For backward compatibility with code that still uses domainConfigs)
|
||||
*/
|
||||
public updateFromDomainConfigs(domainConfigs: IDomainConfig[]): void {
|
||||
const routes: IRouteConfig[] = [];
|
||||
|
||||
// Convert each domain config to routes
|
||||
for (const config of domainConfigs) {
|
||||
routes.push(...this.domainConfigToRoutes(config));
|
||||
}
|
||||
|
||||
// Merge with existing routes that aren't derived from domain configs
|
||||
const nonDomainRoutes = this.routes.filter(r =>
|
||||
!r.name || !r.name.includes('for '));
|
||||
|
||||
this.updateRoutes([...nonDomainRoutes, ...routes]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the route configuration and return any warnings
|
||||
|
@ -61,8 +61,8 @@ export class TimeoutManager {
|
||||
* Calculate effective max lifetime based on connection type
|
||||
*/
|
||||
public getEffectiveMaxLifetime(record: IConnectionRecord): number {
|
||||
// Use domain-specific timeout from forwarding.advanced if available
|
||||
const baseTimeout = record.domainConfig?.forwarding?.advanced?.timeout ||
|
||||
// Use route-specific timeout if available from the routeConfig
|
||||
const baseTimeout = record.routeConfig?.action.advanced?.timeout ||
|
||||
this.settings.maxConnectionLifetime ||
|
||||
86400000; // 24 hours default
|
||||
|
||||
|
Reference in New Issue
Block a user