@@ -211,6 +211,13 @@ export class Grid {
211211 } ) ;
212212 }
213213
214+ /**
215+ * Check whether the base URL is set to its default.
216+ */
217+ #baseURLOverridden( ) : boolean {
218+ return this . baseURL !== 'https://api.grid.is' ;
219+ }
220+
214221 protected defaultQuery ( ) : Record < string , string | undefined > | undefined {
215222 return this . _options . defaultQuery ;
216223 }
@@ -260,11 +267,16 @@ export class Grid {
260267 return Errors . APIError . generate ( status , error , message , headers ) ;
261268 }
262269
263- buildURL ( path : string , query : Record < string , unknown > | null | undefined ) : string {
270+ buildURL (
271+ path : string ,
272+ query : Record < string , unknown > | null | undefined ,
273+ defaultBaseURL ?: string | undefined ,
274+ ) : string {
275+ const baseURL = ( ! this . #baseURLOverridden( ) && defaultBaseURL ) || this . baseURL ;
264276 const url =
265277 isAbsoluteURL ( path ) ?
266278 new URL ( path )
267- : new URL ( this . baseURL + ( this . baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
279+ : new URL ( baseURL + ( baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
268280
269281 const defaultQuery = this . defaultQuery ( ) ;
270282 if ( ! isEmptyObj ( defaultQuery ) ) {
@@ -624,9 +636,9 @@ export class Grid {
624636 { retryCount = 0 } : { retryCount ?: number } = { } ,
625637 ) : { req : FinalizedRequestInit ; url : string ; timeout : number } {
626638 const options = { ...inputOptions } ;
627- const { method, path, query } = options ;
639+ const { method, path, query, defaultBaseURL } = options ;
628640
629- const url = this . buildURL ( path ! , query as Record < string , unknown > ) ;
641+ const url = this . buildURL ( path ! , query as Record < string , unknown > , defaultBaseURL ) ;
630642 if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
631643 options . timeout = options . timeout ?? this . timeout ;
632644 const { bodyHeaders, body } = this . buildBody ( { options } ) ;
0 commit comments