@@ -106,6 +106,19 @@ export function parse(url: string): Dsn {
106106}
107107
108108const DEFAULT_PORT = 6041 ;
109+ const CLOUD_DEFAULT_PORT = 443 ;
110+
111+ function isCloudServiceHost ( host : string ) : boolean {
112+ const normalizedHost = host . toLowerCase ( ) ;
113+ return (
114+ normalizedHost . includes ( "cloud.tdengine.com" ) ||
115+ normalizedHost . includes ( "cloud.taosdata.com" )
116+ ) ;
117+ }
118+
119+ function getDefaultPortForHost ( host : string ) : number {
120+ return isCloudServiceHost ( host ) ? CLOUD_DEFAULT_PORT : DEFAULT_PORT ;
121+ }
109122
110123/**
111124 * Parse comma-separated host list. Supports IPv6 in brackets.
@@ -136,14 +149,14 @@ function parseHostList(hostStr: string): Address[] {
136149 ) ;
137150 }
138151 const ipv6Host = hostStr . slice ( i + 1 , closeBracket ) ;
139- let port = DEFAULT_PORT ;
152+ let port = getDefaultPortForHost ( ipv6Host ) ;
140153 let next = closeBracket + 1 ;
141154 if ( next < hostStr . length && hostStr [ next ] === ":" ) {
142155 const portEnd = hostStr . indexOf ( "," , next ) ;
143156 const portStr = portEnd === - 1
144157 ? hostStr . slice ( next + 1 )
145158 : hostStr . slice ( next + 1 , portEnd ) ;
146- port = parsePort ( portStr , hostStr ) ;
159+ port = parsePort ( portStr , hostStr , ipv6Host ) ;
147160 i = portEnd === - 1 ? hostStr . length : portEnd ;
148161 } else {
149162 i = next ;
@@ -159,10 +172,10 @@ function parseHostList(hostStr: string): Address[] {
159172 const lastColon = segment . lastIndexOf ( ":" ) ;
160173 if ( lastColon !== - 1 ) {
161174 const host = segment . slice ( 0 , lastColon ) ;
162- const port = parsePort ( segment . slice ( lastColon + 1 ) , hostStr ) ;
175+ const port = parsePort ( segment . slice ( lastColon + 1 ) , hostStr , host ) ;
163176 hosts . push ( { host, port } ) ;
164177 } else {
165- hosts . push ( { host : segment , port : DEFAULT_PORT } ) ;
178+ hosts . push ( { host : segment , port : getDefaultPortForHost ( segment ) } ) ;
166179 }
167180 i = commaIndex === - 1 ? hostStr . length : commaIndex ;
168181 }
@@ -171,9 +184,12 @@ function parseHostList(hostStr: string): Address[] {
171184 return hosts ;
172185}
173186
174- function parsePort ( portStr : string , context : string ) : number {
187+ function parsePort ( portStr : string , context : string , hostForDefault ?: string ) : number {
175188 // If port string is empty, use default port
176189 if ( portStr . length === 0 ) {
190+ if ( hostForDefault ) {
191+ return getDefaultPortForHost ( hostForDefault ) ;
192+ }
177193 return DEFAULT_PORT ;
178194 }
179195 // Validate that port string contains only digits
0 commit comments