diff --git a/.changeset/real-llamas-accept.md b/.changeset/real-llamas-accept.md new file mode 100644 index 00000000000..7e76dea0122 --- /dev/null +++ b/.changeset/real-llamas-accept.md @@ -0,0 +1,5 @@ +--- +"@remix-run/deno": patch +--- + +Forward Deno ServeHandlerInfo to getLoadContext diff --git a/contributors.yml b/contributors.yml index ef460350f43..cbbf20f9ecd 100644 --- a/contributors.yml +++ b/contributors.yml @@ -79,6 +79,7 @@ - benwis - bgschiller - binajmen +- blaine-arcjet - bmac - bmarvinb - bmontalvo diff --git a/packages/remix-deno/server.ts b/packages/remix-deno/server.ts index a9b88ebc0d5..df53d675ea4 100644 --- a/packages/remix-deno/server.ts +++ b/packages/remix-deno/server.ts @@ -11,6 +11,26 @@ function defaultCacheControl(url: URL, assetsPublicPath = "/build/") { } } +type UnixAddr = { + transport: "unix" | "unixpacket"; + path: string; +}; + +type NetAddr = { + transport: "tcp" | "udp"; + hostname: string; + port: number; +}; + +type ServeUnixHandlerInfo = { + remoteAddr: UnixAddr; +}; + +type ServeHandlerInfo = { + remoteAddr: NetAddr; + completed: Promise; +}; + export function createRequestHandler< Context extends AppLoadContext | undefined = undefined, >({ @@ -20,13 +40,19 @@ export function createRequestHandler< }: { build: ServerBuild; mode?: string; - getLoadContext?: (request: Request) => Promise | Context; + getLoadContext?: ( + request: Request, + info: ServeHandlerInfo | ServeUnixHandlerInfo + ) => Promise | Context; }) { const handleRequest = createRemixRequestHandler(build, mode); - return async (request: Request) => { + return async ( + request: Request, + info: ServeHandlerInfo | ServeUnixHandlerInfo + ) => { try { - const loadContext = await getLoadContext?.(request); + const loadContext = await getLoadContext?.(request, info); return handleRequest(request, loadContext); } catch (error: unknown) { @@ -96,7 +122,10 @@ export function createRequestHandlerWithStaticFiles< }: { build: ServerBuild; mode?: string; - getLoadContext?: (request: Request) => Promise | Context; + getLoadContext?: ( + request: Request, + info: ServeHandlerInfo | ServeUnixHandlerInfo + ) => Promise | Context; staticFiles?: { cacheControl?: string | ((url: URL) => string); publicDir?: string; @@ -105,7 +134,10 @@ export function createRequestHandlerWithStaticFiles< }) { const remixHandler = createRequestHandler({ build, mode, getLoadContext }); - return async (request: Request) => { + return async ( + request: Request, + info: ServeHandlerInfo | ServeUnixHandlerInfo + ) => { try { return await serveStaticFiles(request, staticFiles); } catch (error: unknown) { @@ -114,6 +146,6 @@ export function createRequestHandlerWithStaticFiles< } } - return remixHandler(request); + return remixHandler(request, info); }; }