Skip to content

Commit 0cf16f4

Browse files
committed
feat: expose endpoint property
There can be multiple instances of the client in an application so expose a property that holds the endpoint being queried to help trace where data comes from in an application
1 parent b243313 commit 0cf16f4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/client/src/client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ const defaultValues = {
2727
}
2828

2929
export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV1HttpApiClient {
30+
public endpoint: URL
3031
private started: boolean
3132
private readonly httpQueue: PQueue
3233
private readonly shutDownController: AbortController
33-
private readonly clientUrl: URL
3434
private readonly timeout: number
3535
private readonly contentRouting: ContentRouting
3636
private readonly peerRouting: PeerRouting
@@ -51,7 +51,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
5151
concurrency: init.concurrentRequests ?? defaultValues.concurrentRequests
5252
})
5353
this.inFlightRequests = new Map() // Tracks in-flight requests to avoid duplicate requests
54-
this.clientUrl = url instanceof URL ? url : new URL(url)
54+
this.endpoint = url instanceof URL ? url : new URL(url)
5555
this.timeout = init.timeout ?? defaultValues.timeout
5656
this.filterAddrs = init.filterAddrs
5757
this.filterProtocols = init.filterProtocols
@@ -118,7 +118,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
118118
await onStart.promise
119119

120120
// https://specs.ipfs.tech/routing/http-routing-v1/
121-
const url = new URL(`${this.clientUrl}routing/v1/providers/${cid}`)
121+
const url = new URL(`${this.endpoint}routing/v1/providers/${cid}`)
122122

123123
this.#addFilterParams(url, options.filterAddrs, options.filterProtocols)
124124
const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal }
@@ -197,7 +197,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
197197
await onStart.promise
198198

199199
// https://specs.ipfs.tech/routing/http-routing-v1/
200-
const url = new URL(`${this.clientUrl}routing/v1/peers/${peerId.toCID().toString()}`)
200+
const url = new URL(`${this.endpoint}routing/v1/peers/${peerId.toCID().toString()}`)
201201
this.#addFilterParams(url, options.filterAddrs, options.filterProtocols)
202202

203203
const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal }
@@ -264,7 +264,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
264264
})
265265

266266
// https://specs.ipfs.tech/routing/http-routing-v1/
267-
const resource = `${this.clientUrl}routing/v1/ipns/${libp2pKey}`
267+
const resource = `${this.endpoint}routing/v1/ipns/${libp2pKey}`
268268

269269
try {
270270
await onStart.promise
@@ -336,7 +336,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
336336
})
337337

338338
// https://specs.ipfs.tech/routing/http-routing-v1/
339-
const resource = `${this.clientUrl}routing/v1/ipns/${libp2pKey}`
339+
const resource = `${this.endpoint}routing/v1/ipns/${libp2pKey}`
340340

341341
try {
342342
await onStart.promise

packages/client/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export type GetProvidersOptions = FilterOptions & AbortOptions
169169
export type GetPeersOptions = FilterOptions & AbortOptions
170170

171171
export interface DelegatedRoutingV1HttpApiClient {
172+
/**
173+
* Where this client sends routing requests
174+
*/
175+
endpoint: URL
176+
172177
/**
173178
* Returns an async generator of {@link PeerRecord}s that can provide the
174179
* content for the passed {@link CID}

0 commit comments

Comments
 (0)