Skip to content

Commit

Permalink
fix(fetchWithEvent): handle undefined init
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 6, 2023
1 parent ade2773 commit c84c811
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/utils/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { H3Event } from "../event";
import type { RequestHeaders } from "../types";
import type { H3EventContext, RequestHeaders } from "../types";
import { getMethod, getRequestHeaders } from "./request";
import { readRawBody } from "./body";
import { splitCookiesString } from "./cookie";
Expand Down Expand Up @@ -133,13 +133,12 @@ export function getProxyRequestHeaders(event: H3Event) {
export function fetchWithEvent(
event: H3Event,
req: RequestInfo | URL,
init?: RequestInit,
init?: RequestInit & { context?: H3EventContext },
options?: { fetch: typeof fetch }
) {
return _getFetch(options?.fetch)(req, {
return _getFetch(options?.fetch)(req, <RequestInit>{
...init,
// @ts-ignore (context is used for unenv and local fetch)
context: init.context || event.context,
context: init?.context || event.context,
headers: {
...getProxyRequestHeaders(event),
...init?.headers,
Expand Down

0 comments on commit c84c811

Please sign in to comment.