@@ -183,6 +183,7 @@ function wrapMiddlewares(middlewares: Middleware[], fetch: Fetch): Fetch {
183
183
return fetch ( url , init )
184
184
}
185
185
const current = middlewares [ index ]
186
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
186
187
return await current ! ( url , init , ( nextUrl , nextInit ) =>
187
188
handler ( index + 1 , nextUrl , nextInit ) ,
188
189
)
@@ -228,7 +229,7 @@ function createFetch<OP>(fetch: _TypedFetch<OP>): TypedFetch<OP> {
228
229
}
229
230
230
231
function fetcher < Paths > ( ) {
231
- let baseUrl = ''
232
+ let baseUrl = '' as string | ( ( ) => string )
232
233
let defaultInit : RequestInit = { }
233
234
const middlewares : Middleware [ ] = [ ]
234
235
const fetch = wrapMiddlewares ( middlewares , fetchJson )
@@ -246,15 +247,17 @@ function fetcher<Paths>() {
246
247
create : ( ( queryParams ?: Record < string , true | 1 > ) =>
247
248
createFetch ( ( payload , init ) =>
248
249
fetchUrl ( {
249
- baseUrl : baseUrl || '' ,
250
+ baseUrl :
251
+ init ?. baseUrl ??
252
+ ( typeof baseUrl === 'function' ? baseUrl ( ) : baseUrl ) ,
250
253
path : path as string ,
251
254
method : method as Method ,
252
255
queryParams : Object . keys ( queryParams || { } ) ,
253
256
payload,
254
257
init : mergeRequestInit ( defaultInit , init ) ,
255
258
fetch,
256
259
} ) ,
257
- ) ) as CreateFetch < M , Paths [ P ] [ M ] > ,
260
+ ) ) as unknown as CreateFetch < M , Paths [ P ] [ M ] > ,
258
261
} ) ,
259
262
} ) ,
260
263
}
0 commit comments