diff --git a/packages/remix-cloudflare-pages/worker.ts b/packages/remix-cloudflare-pages/worker.ts index cacc41e38a4..5b24e6e36b9 100644 --- a/packages/remix-cloudflare-pages/worker.ts +++ b/packages/remix-cloudflare-pages/worker.ts @@ -8,14 +8,18 @@ import { createRequestHandler as createRemixRequestHandler } from "@remix-run/cl * You can think of this as an escape hatch that allows you to pass * environment/platform-specific values through to your loader/action. */ -export type GetLoadContextFunction = ( - context: Parameters>[0] +export type GetLoadContextFunction< + Env = unknown, + Params extends string = any, + Data extends Record = Record +> = ( + context: EventContext ) => Promise | AppLoadContext; export type RequestHandler = PagesFunction; export interface createPagesFunctionHandlerParams { - build: ServerBuild; + build: ServerBuild | (() => ServerBuild | Promise); getLoadContext?: GetLoadContextFunction; mode?: string; } diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index b5c3147c3b3..a477d3db58a 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -36,7 +36,7 @@ export type RequestHandler = ( ) => Promise; export type CreateRequestHandlerFunction = ( - build: ServerBuild | (() => Promise), + build: ServerBuild | (() => ServerBuild | Promise), mode?: string ) => RequestHandler; diff --git a/templates/unstable-vite-cloudflare/functions/[[path]].ts b/templates/unstable-vite-cloudflare/functions/[[path]].ts index 095142281f5..6ca71e51aa9 100644 --- a/templates/unstable-vite-cloudflare/functions/[[path]].ts +++ b/templates/unstable-vite-cloudflare/functions/[[path]].ts @@ -1,13 +1,14 @@ import { type ServerBuild } from "@remix-run/cloudflare"; import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages"; -// eslint-disable-next-line import/no-unresolved -import * as _build from "../build/server"; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const build: ServerBuild = _build as any; +const build = async (): Promise => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + // eslint-disable-next-line import/no-unresolved + return import("../build/server"); +}; export const onRequest = createPagesFunctionHandler({ build, getLoadContext: (context) => ({ env: context.env }), - mode: build.mode, });