fix(smartproxy): Update dynamic port mapping to support
This commit is contained in:
		| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@push.rocks/smartproxy', | ||||
|   version: '16.0.3', | ||||
|   version: '16.0.4', | ||||
|   description: 'A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.' | ||||
| } | ||||
|   | ||||
| @@ -447,6 +447,8 @@ export class NetworkProxy implements IMetricsTracker { | ||||
|  | ||||
|     // Create legacy proxy configs for the router | ||||
|     // This is only needed for backward compatibility with ProxyRouter | ||||
|      | ||||
|     const defaultPort = 443; // Default port for HTTPS when using 'preserve' | ||||
|     // and will be removed in the future | ||||
|     const legacyConfigs: IReverseProxyConfig[] = []; | ||||
|  | ||||
| @@ -472,7 +474,8 @@ export class NetworkProxy implements IMetricsTracker { | ||||
|         ? route.action.target.host | ||||
|         : [route.action.target.host]; | ||||
|  | ||||
|       const targetPort = route.action.target.port; | ||||
|       // Handle 'preserve' port value | ||||
|       const targetPort = route.action.target.port === 'preserve' ? defaultPort : route.action.target.port; | ||||
|  | ||||
|       // Get certificate information | ||||
|       const certData = certificateUpdates.get(domain); | ||||
|   | ||||
| @@ -540,7 +540,7 @@ export class RequestHandler { | ||||
|             this.logger.debug(`Resolved function-based port to: ${resolvedPort}`); | ||||
|           } | ||||
|         } else { | ||||
|           targetPort = matchingRoute.action.target.port; | ||||
|           targetPort = matchingRoute.action.target.port === 'preserve' ? routeContext.port : matchingRoute.action.target.port as number; | ||||
|         } | ||||
|  | ||||
|         // Select a single host if an array was provided | ||||
| @@ -760,7 +760,7 @@ export class RequestHandler { | ||||
|             this.logger.debug(`Resolved HTTP/2 function-based port to: ${resolvedPort}`); | ||||
|           } | ||||
|         } else { | ||||
|           targetPort = matchingRoute.action.target.port; | ||||
|           targetPort = matchingRoute.action.target.port === 'preserve' ? routeContext.port : matchingRoute.action.target.port as number; | ||||
|         } | ||||
|  | ||||
|         // Select a single host if an array was provided | ||||
|   | ||||
| @@ -204,7 +204,7 @@ export class WebSocketHandler { | ||||
|             targetPort = route.action.target.port(toBaseContext(routeContext)); | ||||
|             this.logger.debug(`Resolved function-based port for WebSocket: ${targetPort}`); | ||||
|           } else { | ||||
|             targetPort = route.action.target.port; | ||||
|             targetPort = route.action.target.port === 'preserve' ? routeContext.port : route.action.target.port as number; | ||||
|           } | ||||
|  | ||||
|           // Select a single host if an array was provided | ||||
|   | ||||
| @@ -69,8 +69,7 @@ export interface IRouteContext { | ||||
|  */ | ||||
| export interface IRouteTarget { | ||||
|   host: string | string[] | ((context: IRouteContext) => string | string[]);  // Host or hosts with optional function for dynamic resolution | ||||
|   port: number | ((context: IRouteContext) => number);  // Port with optional function for dynamic mapping | ||||
|   preservePort?: boolean;   // Use incoming port as target port (ignored if port is a function) | ||||
|   port: number | 'preserve' | ((context: IRouteContext) => number);  // Port with optional function for dynamic mapping (use 'preserve' to keep the incoming port) | ||||
| } | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -434,8 +434,8 @@ export class RouteConnectionHandler { | ||||
|         this.connectionManager.cleanupConnection(record, 'port_mapping_error'); | ||||
|         return; | ||||
|       } | ||||
|     } else if (action.target.preservePort) { | ||||
|       // Use incoming port if preservePort is true | ||||
|     } else if (action.target.port === 'preserve') { | ||||
|       // Use incoming port if port is 'preserve' | ||||
|       targetPort = record.localPort; | ||||
|     } else { | ||||
|       // Use static port from configuration | ||||
| @@ -525,7 +525,7 @@ export class RouteConnectionHandler { | ||||
|       let targetPort: number; | ||||
|       if (typeof action.target.port === 'function') { | ||||
|         targetPort = action.target.port(routeContext); | ||||
|       } else if (action.target.preservePort) { | ||||
|       } else if (action.target.port === 'preserve') { | ||||
|         targetPort = record.localPort; | ||||
|       } else { | ||||
|         targetPort = action.target.port; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user