fix: move to mocked-exports
rather than implicit unenv
dep (#3232)
This commit is contained in:
parent
5623f87607
commit
1bf113a960
8 changed files with 43 additions and 14 deletions
|
@ -5,11 +5,8 @@ import {
|
|||
defineLazyEventHandler,
|
||||
toNodeListener,
|
||||
} from 'h3'
|
||||
import { fetchNodeRequestHandler } from 'node-mock-http'
|
||||
import { createFetch } from 'ofetch'
|
||||
import {
|
||||
createCall,
|
||||
createFetch as createLocalFetch,
|
||||
} from 'unenv/runtime/fetch/index'
|
||||
|
||||
const handlers = [
|
||||
{
|
||||
|
@ -52,12 +49,16 @@ export default defineNuxtPlugin(async () => {
|
|||
// @ts-expect-error TODO: fix
|
||||
h3App.use(config.app.baseURL, router)
|
||||
|
||||
const localCall = createCall(toNodeListener(h3App) as any)
|
||||
const localFetch = createLocalFetch(localCall, globalThis.fetch)
|
||||
const nodeHandler = toNodeListener(h3App)
|
||||
const localFetch: typeof fetch = async (input, init) => {
|
||||
if (!input.toString().startsWith('/')) {
|
||||
return globalThis.fetch(input.toString(), init)
|
||||
}
|
||||
return await fetchNodeRequestHandler(nodeHandler, input.toString(), init)
|
||||
}
|
||||
|
||||
// @ts-expect-error error types are subtly different here in a future nitro version
|
||||
globalThis.$fetch = createFetch({
|
||||
// @ts-expect-error slight differences in api
|
||||
fetch: localFetch,
|
||||
Headers,
|
||||
defaults: { baseURL: config.app.baseURL },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue