(config: ApiClientConfig)
| 26 | } |
| 27 | |
| 28 | export function createApiClient(config: ApiClientConfig): ApiClient { |
| 29 | assert(typeof config.baseUrl === "string", "baseUrl must be a string"); |
| 30 | |
| 31 | const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl); |
| 32 | |
| 33 | const link = new RPCLink({ |
| 34 | url: `${normalizedBaseUrl}/orpc`, |
| 35 | async fetch(request, init) { |
| 36 | const headers = new Headers(request.headers); |
| 37 | if (config.authToken) { |
| 38 | headers.set("Authorization", `Bearer ${config.authToken}`); |
| 39 | } |
| 40 | |
| 41 | return fetch(request.url, { |
| 42 | body: await request.blob(), |
| 43 | headers, |
| 44 | method: request.method, |
| 45 | signal: request.signal, |
| 46 | ...init, |
| 47 | }); |
| 48 | }, |
| 49 | }); |
| 50 | |
| 51 | return createClient(link); |
| 52 | } |
no test coverage detected