@@ -119,7 +119,7 @@ export class HermesClient {
119
119
query ?: string ;
120
120
filter ?: string ;
121
121
} ) : Promise < PriceFeedMetadata [ ] > {
122
- const url = new URL ( "v2/ price_feeds", this . baseURL ) ;
122
+ const url = this . buildURL ( " price_feeds") ;
123
123
if ( options ) {
124
124
this . appendUrlSearchParams ( url , options ) ;
125
125
}
@@ -144,7 +144,7 @@ export class HermesClient {
144
144
encoding ?: EncodingType ;
145
145
parsed ?: boolean ;
146
146
} ) : 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") ;
148
148
if ( options ) {
149
149
this . appendUrlSearchParams ( url , options ) ;
150
150
}
@@ -175,7 +175,7 @@ export class HermesClient {
175
175
ignoreInvalidPriceIds ?: boolean ;
176
176
}
177
177
) : Promise < PriceUpdate > {
178
- const url = new URL ( "v2/ updates/price/latest", this . baseURL ) ;
178
+ const url = this . buildURL ( " updates/price/latest") ;
179
179
for ( const id of ids ) {
180
180
url . searchParams . append ( "ids[]" , id ) ;
181
181
}
@@ -211,7 +211,7 @@ export class HermesClient {
211
211
ignoreInvalidPriceIds ?: boolean ;
212
212
}
213
213
) : Promise < PriceUpdate > {
214
- const url = new URL ( `v2/ updates/price/${ publishTime } `, this . baseURL ) ;
214
+ const url = this . buildURL ( ` updates/price/${ publishTime } `) ;
215
215
for ( const id of ids ) {
216
216
url . searchParams . append ( "ids[]" , id ) ;
217
217
}
@@ -251,7 +251,7 @@ export class HermesClient {
251
251
ignoreInvalidPriceIds ?: boolean ;
252
252
}
253
253
) : Promise < EventSource > {
254
- const url = new URL ( "v2/ updates/price/stream", this . baseURL ) ;
254
+ const url = this . buildURL ( " updates/price/stream") ;
255
255
ids . forEach ( ( id ) => {
256
256
url . searchParams . append ( "ids[]" , id ) ;
257
257
} ) ;
@@ -288,10 +288,7 @@ export class HermesClient {
288
288
ignoreInvalidPriceIds ?: boolean ;
289
289
}
290
290
) : 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` ) ;
295
292
for ( const id of ids ) {
296
293
url . searchParams . append ( "ids[]" , id ) ;
297
294
}
@@ -314,4 +311,13 @@ export class HermesClient {
314
311
}
315
312
} ) ;
316
313
}
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
+ }
317
323
}
0 commit comments