From d2e0999086481375943526cc1206a4f7fd8b2023 Mon Sep 17 00:00:00 2001 From: Curt Tudor Date: Thu, 16 Jan 2025 16:00:04 -0700 Subject: [PATCH] fix: Correct sub-domain Service-routing issue (#238) --- src/ZitiFirstStrategy.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ZitiFirstStrategy.ts b/src/ZitiFirstStrategy.ts index 1280487..5107a74 100644 --- a/src/ZitiFirstStrategy.ts +++ b/src/ZitiFirstStrategy.ts @@ -608,14 +608,21 @@ class ZitiFirstStrategy extends CacheFirst /* NetworkFirst */ { } else { - newUrl.hostname = this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.target.service; - newUrl.port = this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.target.port; - - if ( - isEqual(newUrl.port, this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.self.port) || - isEqual(newUrl.port, this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.loadbalancer.port) - ) { - newUrl.port = ''; + // Don't muck with URL only because top-level domain of target matches the top-level domain of the load-balancer. + // Only do that if the entire hostname matches, or else sub-domains represented by different Services will be routed + // to the wrong place. + if (!isEqual(newUrl.hostname, this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.self.host)) { + + newUrl.hostname = this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.target.service; + newUrl.port = this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.target.port; + + if ( + isEqual(newUrl.port, this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.bootstrapper.self.port) || + isEqual(newUrl.port, this._zitiBrowzerServiceWorkerGlobalScope._zitiConfig.browzer.loadbalancer.port) + ) { + newUrl.port = ''; + } + } var pathnameArray = newUrl.pathname.split('/');