@@ -119,7 +119,7 @@ export class HermesClient {
119119 query ?: string ;
120120 filter ?: string ;
121121 } ) : Promise < PriceFeedMetadata [ ] > {
122- const url = new URL ( "v2/ price_feeds", this . baseURL ) ;
122+ const url = this . buildURL ( " price_feeds") ;
123123 if ( options ) {
124124 this . appendUrlSearchParams ( url , options ) ;
125125 }
@@ -144,7 +144,7 @@ export class HermesClient {
144144 encoding ?: EncodingType ;
145145 parsed ?: boolean ;
146146 } ) : Promise < PublisherCaps > {
147- const url = new URL ( "v2/ updates/publisher_stake_caps/latest", this . baseURL ) ;
147+ const url = this . buildURL ( " updates/publisher_stake_caps/latest") ;
148148 if ( options ) {
149149 this . appendUrlSearchParams ( url , options ) ;
150150 }
@@ -175,7 +175,7 @@ export class HermesClient {
175175 ignoreInvalidPriceIds ?: boolean ;
176176 }
177177 ) : Promise < PriceUpdate > {
178- const url = new URL ( "v2/ updates/price/latest", this . baseURL ) ;
178+ const url = this . buildURL ( " updates/price/latest") ;
179179 for ( const id of ids ) {
180180 url . searchParams . append ( "ids[]" , id ) ;
181181 }
@@ -211,7 +211,7 @@ export class HermesClient {
211211 ignoreInvalidPriceIds ?: boolean ;
212212 }
213213 ) : Promise < PriceUpdate > {
214- const url = new URL ( `v2/ updates/price/${ publishTime } `, this . baseURL ) ;
214+ const url = this . buildURL ( ` updates/price/${ publishTime } `) ;
215215 for ( const id of ids ) {
216216 url . searchParams . append ( "ids[]" , id ) ;
217217 }
@@ -251,7 +251,7 @@ export class HermesClient {
251251 ignoreInvalidPriceIds ?: boolean ;
252252 }
253253 ) : Promise < EventSource > {
254- const url = new URL ( "v2/ updates/price/stream", this . baseURL ) ;
254+ const url = this . buildURL ( " updates/price/stream") ;
255255 ids . forEach ( ( id ) => {
256256 url . searchParams . append ( "ids[]" , id ) ;
257257 } ) ;
@@ -288,10 +288,7 @@ export class HermesClient {
288288 ignoreInvalidPriceIds ?: boolean ;
289289 }
290290 ) : Promise < TwapsResponse > {
291- const url = new URL (
292- `v2/updates/twap/${ window_seconds } /latest` ,
293- this . baseURL
294- ) ;
291+ const url = this . buildURL ( `updates/twap/${ window_seconds } /latest` ) ;
295292 for ( const id of ids ) {
296293 url . searchParams . append ( "ids[]" , id ) ;
297294 }
@@ -314,4 +311,13 @@ export class HermesClient {
314311 }
315312 } ) ;
316313 }
314+
315+ private buildURL ( endpoint : string ) {
316+ return new URL (
317+ `./v2/${ endpoint } ` ,
318+ // We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
319+ // path relative to the parent.
320+ `${ this . baseURL } ${ this . baseURL . endsWith ( "/" ) ? "" : "/" } `
321+ ) ;
322+ }
317323}
0 commit comments