@@ -17,12 +17,12 @@ import type {
1717 NitroRuntimeHooks ,
1818} from "nitropack/types" ;
1919import type { NitroAsyncContext } from "nitropack/types" ;
20- import type { $Fetch , NitroFetchRequest } from "nitropack/types" ;
2120import { Headers , createFetch } from "ofetch" ;
2221import {
23- createCall ,
24- createFetch as createLocalFetch ,
25- } from "unenv/runtime/fetch/index" ;
22+ fetchNodeRequestHandler ,
23+ callNodeRequestHandler ,
24+ type AbstractRequest ,
25+ } from "node-mock-http" ;
2626import errorHandler from "#nitro-internal-virtual/error-handler" ;
2727import { plugins } from "#nitro-internal-virtual/plugins" ;
2828import { handlers } from "#nitro-internal-virtual/server-handlers" ;
@@ -85,14 +85,20 @@ function createNitroApp(): NitroApp {
8585 preemptive : true ,
8686 } ) ;
8787
88- // Create local fetch callers
89- const localCall = createCall ( toNodeListener ( h3App ) as any ) ;
90- // prettier-ignore
91- const _localFetch = createLocalFetch ( localCall , ( u , i ) => globalThis . fetch ( u , i ) ) ;
92- const localFetch : typeof fetch = ( input , init ) =>
93- _localFetch ( input as RequestInfo , init as any ) . then ( ( response ) =>
94- normalizeFetchResponse ( response )
95- ) ;
88+ // Create local fetch caller
89+ const nodeHandler = toNodeListener ( h3App ) ;
90+ const localCall = ( aRequest : AbstractRequest ) =>
91+ callNodeRequestHandler ( nodeHandler , aRequest ) ;
92+ const localFetch : typeof fetch = ( input , init ) => {
93+ if ( ! input . toString ( ) . startsWith ( "/" ) ) {
94+ return globalThis . fetch ( input , init ) ;
95+ }
96+ return fetchNodeRequestHandler (
97+ nodeHandler ,
98+ input as string /* TODO */ ,
99+ init
100+ ) . then ( ( response ) => normalizeFetchResponse ( response ) ) ;
101+ } ;
96102 const $fetch = createFetch ( {
97103 fetch : localFetch ,
98104 Headers,
0 commit comments