Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Forward Deno ServeHandlerInfo to getLoadContext #10042

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-llamas-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/deno": patch
---

Forward Deno ServeHandlerInfo to getLoadContext
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
- benwis
- bgschiller
- binajmen
- blaine-arcjet
- bmac
- bmarvinb
- bmontalvo
Expand Down
44 changes: 38 additions & 6 deletions packages/remix-deno/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
};

export function createRequestHandler<
Context extends AppLoadContext | undefined = undefined,
>({
Expand All @@ -20,13 +40,19 @@ export function createRequestHandler<
}: {
build: ServerBuild;
mode?: string;
getLoadContext?: (request: Request) => Promise<Context> | Context;
getLoadContext?: (
request: Request,
info: ServeHandlerInfo | ServeUnixHandlerInfo
) => Promise<Context> | 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) {
Expand Down Expand Up @@ -96,7 +122,10 @@ export function createRequestHandlerWithStaticFiles<
}: {
build: ServerBuild;
mode?: string;
getLoadContext?: (request: Request) => Promise<Context> | Context;
getLoadContext?: (
request: Request,
info: ServeHandlerInfo | ServeUnixHandlerInfo
) => Promise<Context> | Context;
staticFiles?: {
cacheControl?: string | ((url: URL) => string);
publicDir?: string;
Expand All @@ -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) {
Expand All @@ -114,6 +146,6 @@ export function createRequestHandlerWithStaticFiles<
}
}

return remixHandler(request);
return remixHandler(request, info);
};
}