diff --git a/.changeset/remove-fetch-polyfill-references-in-adapters.md b/.changeset/remove-fetch-polyfill-references-in-adapters.md new file mode 100644 index 00000000000..bbe261f79e7 --- /dev/null +++ b/.changeset/remove-fetch-polyfill-references-in-adapters.md @@ -0,0 +1,6 @@ +--- +"@remix-run/architect": patch +"@remix-run/express": patch +--- + +remove references to fetch polyfills in node and arc adapters diff --git a/packages/remix-architect/server.ts b/packages/remix-architect/server.ts index 81340c9cc9b..9deda1b3f0a 100644 --- a/packages/remix-architect/server.ts +++ b/packages/remix-architect/server.ts @@ -1,11 +1,5 @@ -import type { - AppLoadContext, - ServerBuild, - Response as NodeResponse, -} from "@remix-run/node"; +import type { AppLoadContext, ServerBuild } from "@remix-run/node"; import { - Headers as NodeHeaders, - Request as NodeRequest, createRequestHandler as createRemixRequestHandler, readableStreamToString, } from "@remix-run/node"; @@ -50,13 +44,13 @@ export function createRequestHandler({ let request = createRemixRequest(event); let loadContext = await getLoadContext?.(event); - let response = (await handleRequest(request, loadContext)) as NodeResponse; + let response = await handleRequest(request, loadContext); return sendRemixResponse(response); }; } -export function createRemixRequest(event: APIGatewayProxyEventV2): NodeRequest { +export function createRemixRequest(event: APIGatewayProxyEventV2): Request { let host = event.headers["x-forwarded-host"] || event.headers.host; let search = event.rawQueryString.length ? `?${event.rawQueryString}` : ""; let scheme = process.env.ARC_SANDBOX ? "http" : "https"; @@ -68,7 +62,7 @@ export function createRemixRequest(event: APIGatewayProxyEventV2): NodeRequest { // requests to contain a signal, so it can detect aborted requests let controller = new AbortController(); - return new NodeRequest(url.href, { + return new Request(url.href, { method: event.requestContext.http.method, headers: createRemixHeaders(event.headers, event.cookies), signal: controller.signal, @@ -84,8 +78,8 @@ export function createRemixRequest(event: APIGatewayProxyEventV2): NodeRequest { export function createRemixHeaders( requestHeaders: APIGatewayProxyEventHeaders, requestCookies?: string[] -): NodeHeaders { - let headers = new NodeHeaders(); +): Headers { + let headers = new Headers(); for (let [header, value] of Object.entries(requestHeaders)) { if (value) { @@ -101,7 +95,7 @@ export function createRemixHeaders( } export async function sendRemixResponse( - nodeResponse: NodeResponse + nodeResponse: Response ): Promise { let cookies: string[] = []; diff --git a/packages/remix-express/server.ts b/packages/remix-express/server.ts index a3f14ce0d54..867d7a9cb79 100644 --- a/packages/remix-express/server.ts +++ b/packages/remix-express/server.ts @@ -1,14 +1,12 @@ +// IDK why this is needed when it's in the tsconfig.......... +// YAY PROJECT REFERENCES! +/// + import type * as express from "express"; -import type { - AppLoadContext, - ServerBuild, - RequestInit as NodeRequestInit, - Response as NodeResponse, -} from "@remix-run/node"; +import type { AppLoadContext, ServerBuild } from "@remix-run/node"; import { createRequestHandler as createRemixRequestHandler, - Headers as NodeHeaders, - Request as NodeRequest, + createReadableStreamFromReadable, writeReadableStreamToWritable, } from "@remix-run/node"; @@ -54,10 +52,7 @@ export function createRequestHandler({ let request = createRemixRequest(req, res); let loadContext = await getLoadContext?.(req, res); - let response = (await handleRequest( - request, - loadContext - )) as NodeResponse; + let response = await handleRequest(request, loadContext); await sendRemixResponse(res, response); } catch (error: unknown) { @@ -70,8 +65,8 @@ export function createRequestHandler({ export function createRemixHeaders( requestHeaders: express.Request["headers"] -): NodeHeaders { - let headers = new NodeHeaders(); +): Headers { + let headers = new Headers(); for (let [key, values] of Object.entries(requestHeaders)) { if (values) { @@ -91,29 +86,30 @@ export function createRemixHeaders( export function createRemixRequest( req: express.Request, res: express.Response -): NodeRequest { +): Request { let url = new URL(`${req.protocol}://${req.get("host")}${req.url}`); // Abort action/loaders once we can no longer write a response let controller = new AbortController(); res.on("close", () => controller.abort()); - let init: NodeRequestInit = { + let init: RequestInit = { method: req.method, headers: createRemixHeaders(req.headers), signal: controller.signal, }; if (req.method !== "GET" && req.method !== "HEAD") { - init.body = req; + init.body = createReadableStreamFromReadable(req); + (init as { duplex: "half" }).duplex = "half"; } - return new NodeRequest(url.href, init); + return new Request(url.href, init); } export async function sendRemixResponse( res: express.Response, - nodeResponse: NodeResponse + nodeResponse: Response ): Promise { res.statusMessage = nodeResponse.statusText; res.status(nodeResponse.status);