mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
fix(client): allow req middlewares to run on empty init
This commit is contained in:
@@ -24,10 +24,11 @@ export class ApiClient {
|
|||||||
this.middlewares = middlewares
|
this.middlewares = middlewares
|
||||||
}
|
}
|
||||||
|
|
||||||
async request<T>(...[url, init]: Parameters<typeof fetch>): Promise<[Response, T]> {
|
async request<T>(...[url, init = {}]: Parameters<typeof fetch>): Promise<[Response, T]> {
|
||||||
const finalInit = init
|
const finalInit = this.middlewares.reduce(
|
||||||
? this.middlewares.reduce((prevInit, middleware) => middleware(url, prevInit), init)
|
(prevInit, middleware) => middleware(url, prevInit),
|
||||||
: undefined
|
init,
|
||||||
|
)
|
||||||
return fetch(url instanceof Request ? url : new URL(url, this.baseUrl), finalInit).then((res) =>
|
return fetch(url instanceof Request ? url : new URL(url, this.baseUrl), finalInit).then((res) =>
|
||||||
Promise.all([Promise.resolve(res), res.json()]),
|
Promise.all([Promise.resolve(res), res.json()]),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user