fix(nuxt): don't use local fetch with an external baseURL (#23884)

This commit is contained in:
Daniel Roe 2023-10-23 21:17:41 +09:00 committed by GitHub
parent 52af4a5684
commit 2dc078ea40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,11 +140,14 @@ export function useFetch<
controller?.abort?.()
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
const isLocalFetch = typeof _request.value === 'string' && _request.value.startsWith('/')
let _$fetch = opts.$fetch || globalThis.$fetch
// Use fetch with request context and headers for server direct API calls
if (import.meta.server && !opts.$fetch && isLocalFetch) {
_$fetch = useRequestFetch()
if (import.meta.server && !opts.$fetch) {
const isLocalFetch = typeof _request.value === 'string' && _request.value.startsWith('/') && (!unref(opts.baseURL) || unref(opts.baseURL)!.startsWith('/'))
if (isLocalFetch) {
_$fetch = useRequestFetch()
}
}
return _$fetch(_request.value, { signal: controller.signal, ..._fetchOptions } as any) as Promise<_ResT>