mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(nuxt): don't use local fetch with an external baseURL
(#23884)
This commit is contained in:
parent
52af4a5684
commit
2dc078ea40
@ -140,11 +140,14 @@ export function useFetch<
|
|||||||
controller?.abort?.()
|
controller?.abort?.()
|
||||||
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
|
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
|
||||||
|
|
||||||
const isLocalFetch = typeof _request.value === 'string' && _request.value.startsWith('/')
|
|
||||||
let _$fetch = opts.$fetch || globalThis.$fetch
|
let _$fetch = opts.$fetch || globalThis.$fetch
|
||||||
|
|
||||||
// Use fetch with request context and headers for server direct API calls
|
// Use fetch with request context and headers for server direct API calls
|
||||||
if (import.meta.server && !opts.$fetch && isLocalFetch) {
|
if (import.meta.server && !opts.$fetch) {
|
||||||
_$fetch = useRequestFetch()
|
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>
|
return _$fetch(_request.value, { signal: controller.signal, ..._fetchOptions } as any) as Promise<_ResT>
|
||||||
|
Loading…
Reference in New Issue
Block a user