From 8dd222443d50e10e06d17fc3dc041b38b2e6eeb3 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sat, 10 May 2025 00:28:35 +0000 Subject: [PATCH] fix: Make SmartProxy work with pure route-based configuration --- .../smart-proxy/route-connection-handler.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ts/proxies/smart-proxy/route-connection-handler.ts b/ts/proxies/smart-proxy/route-connection-handler.ts index c08a0d4..557dd9a 100644 --- a/ts/proxies/smart-proxy/route-connection-handler.ts +++ b/ts/proxies/smart-proxy/route-connection-handler.ts @@ -301,22 +301,28 @@ export class RouteConnectionHandler { // Setup direct connection with default settings let targetHost: string; let targetPort: number; - + if (isRoutedOptions(this.settings) && this.settings.defaults?.target) { // Use defaults from routed configuration targetHost = this.settings.defaults.target.host; targetPort = this.settings.defaults.target.port; - } else { + } else if (this.settings.targetIP && this.settings.toPort) { // Fall back to legacy settings - targetHost = this.settings.targetIP || 'localhost'; + targetHost = this.settings.targetIP; targetPort = this.settings.toPort; + } else { + // No default target available, terminate the connection + console.log(`[${connectionId}] No default target configured. Closing connection.`); + socket.end(); + this.connectionManager.cleanupConnection(record, 'no_default_target'); + return; } - + return this.setupDirectConnection( - socket, - record, - undefined, - serverName, + socket, + record, + undefined, + serverName, initialChunk, undefined, targetHost,