@@ -143,16 +143,24 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
143143 }
144144}
145145
146- /** Builds the gateway hostname from a core hostname by replacing the last two labels with
147- * the given `gatewayurl` suffix (default `gateway.sqlite.cloud`). Returns host unchanged
148- * when it already ends with the suffix (idempotent) or is too short to have a tenant prefix. */
146+ /** Default gateway domain suffix used when `gatewayurl` is not provided. */
147+ const DEFAULT_GATEWAY_DOMAIN = 'gateway.sqlite.cloud'
148+
149+ /** Builds the gateway hostname from a core hostname, swapping its last two labels (the
150+ * TLD) with the given `gatewayurl` suffix.
151+ *
152+ * Example: buildGatewayHost('crvheg7dhk.g4.sqlite.cloud')
153+ * → 'crvheg7dhk.g4.gateway.sqlite.cloud'
154+ *
155+ * Returns `host` unchanged when it already ends with the suffix (idempotent) or when
156+ * it's too short to extract a tenant prefix (eg 'localhost'). */
149157function buildGatewayHost ( host : string , gatewayurl ?: string ) : string {
150158 if ( ! host ) return host
151- const suffix = gatewayurl || 'gateway.sqlite.cloud'
159+ const suffix = gatewayurl || DEFAULT_GATEWAY_DOMAIN
152160 if ( host === suffix || host . endsWith ( '.' + suffix ) ) return host
153- const labels = host . split ( '.' )
154- if ( labels . length < 3 ) return host
155- return labels . slice ( 0 , - 2 ) . join ( '.' ) + '.' + suffix
161+ const parts = host . split ( '.' )
162+ if ( parts . length < 3 ) return host
163+ return parts . slice ( 0 , - 2 ) . join ( '.' ) + '.' + suffix
156164}
157165
158166export default SQLiteCloudWebsocketConnection
0 commit comments