fix(smartproxy): Update dynamic port mapping to support

This commit is contained in:
2025-05-14 18:35:06 +00:00
parent 2d6f06a9b3
commit 340823296a
8 changed files with 495 additions and 10 deletions

View File

@ -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)
}
/**

View File

@ -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;