Skip to content

Commit c84c811

Browse files
committed
fix(fetchWithEvent): handle undefined init
1 parent ade2773 commit c84c811

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/utils/proxy.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { H3Event } from "../event";
2-
import type { RequestHeaders } from "../types";
2+
import type { H3EventContext, RequestHeaders } from "../types";
33
import { getMethod, getRequestHeaders } from "./request";
44
import { readRawBody } from "./body";
55
import { splitCookiesString } from "./cookie";
@@ -133,13 +133,12 @@ export function getProxyRequestHeaders(event: H3Event) {
133133
export function fetchWithEvent(
134134
event: H3Event,
135135
req: RequestInfo | URL,
136-
init?: RequestInit,
136+
init?: RequestInit & { context?: H3EventContext },
137137
options?: { fetch: typeof fetch }
138138
) {
139-
return _getFetch(options?.fetch)(req, {
139+
return _getFetch(options?.fetch)(req, <RequestInit>{
140140
...init,
141-
// @ts-ignore (context is used for unenv and local fetch)
142-
context: init.context || event.context,
141+
context: init?.context || event.context,
143142
headers: {
144143
...getProxyRequestHeaders(event),
145144
...init?.headers,

0 commit comments

Comments
 (0)