@@ -228,6 +228,13 @@ export class Kernel {
228228 } ) ;
229229 }
230230
231+ /**
232+ * Check whether the base URL is set to its default.
233+ */
234+ #baseURLOverridden( ) : boolean {
235+ return this . baseURL !== environments [ this . _options . environment || 'production' ] ;
236+ }
237+
231238 protected defaultQuery ( ) : Record < string , string | undefined > | undefined {
232239 return this . _options . defaultQuery ;
233240 }
@@ -277,11 +284,16 @@ export class Kernel {
277284 return Errors . APIError . generate ( status , error , message , headers ) ;
278285 }
279286
280- buildURL ( path : string , query : Record < string , unknown > | null | undefined ) : string {
287+ buildURL (
288+ path : string ,
289+ query : Record < string , unknown > | null | undefined ,
290+ defaultBaseURL ?: string | undefined ,
291+ ) : string {
292+ const baseURL = ( ! this . #baseURLOverridden( ) && defaultBaseURL ) || this . baseURL ;
281293 const url =
282294 isAbsoluteURL ( path ) ?
283295 new URL ( path )
284- : new URL ( this . baseURL + ( this . baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
296+ : new URL ( baseURL + ( baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
285297
286298 const defaultQuery = this . defaultQuery ( ) ;
287299 if ( ! isEmptyObj ( defaultQuery ) ) {
@@ -622,9 +634,9 @@ export class Kernel {
622634 { retryCount = 0 } : { retryCount ?: number } = { } ,
623635 ) : { req : FinalizedRequestInit ; url : string ; timeout : number } {
624636 const options = { ...inputOptions } ;
625- const { method, path, query } = options ;
637+ const { method, path, query, defaultBaseURL } = options ;
626638
627- const url = this . buildURL ( path ! , query as Record < string , unknown > ) ;
639+ const url = this . buildURL ( path ! , query as Record < string , unknown > , defaultBaseURL ) ;
628640 if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
629641 options . timeout = options . timeout ?? this . timeout ;
630642 const { bodyHeaders, body } = this . buildBody ( { options } ) ;
0 commit comments