This repository was archived by the owner on Feb 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace deprecated vercel entrypoint
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { IncomingMessage, ServerResponse } from "node:http"; | ||
import { tinyassert } from "@hiogawa/utils"; | ||
import * as build from "@remix-run/dev/server-build"; | ||
import { createRequestHandler } from "@remix-run/express"; | ||
|
||
// borrow "@remix-run/express" adapter for vercel serverless deployment | ||
// since "@remix-run/vercel" is going to deprecate (https://github.com/remix-run/remix/pull/5964) | ||
// in favor of vercel's official integration (https://github.com/vercel/vercel/blob/da046d85de8121e6c851af8e51aff81984646e0b/packages/remix/defaults/server-node.mjs) | ||
|
||
const handleRequest = createRequestHandler({ build }); | ||
|
||
export default async function vercelEntrypoint( | ||
req: IncomingMessage, | ||
res: ServerResponse | ||
): Promise<void> { | ||
// a few patches to fake express style Request/Response | ||
// https://github.com/remix-run/remix/blame/71e94aa8a84cd9b63669dc9d826cbcbb0d2195a1/packages/remix-express/server.ts | ||
// https://github.com/remix-run/remix/blame/71e94aa8a84cd9b63669dc9d826cbcbb0d2195a1/packages/remix-vercel/server.ts | ||
|
||
const req2 = req as any; | ||
const res2 = res as any; | ||
|
||
req2.get = (arg: unknown) => { | ||
tinyassert(arg === "host"); | ||
return req.headers["x-forwarded-host"] || req.headers["host"]; | ||
}; | ||
|
||
req2.protocol = req.headers["x-forwarded-proto"] || "https"; | ||
|
||
res2.status = (arg: unknown) => { | ||
tinyassert(typeof arg === "number"); | ||
res.statusCode = arg; | ||
}; | ||
|
||
res2.append = (k: unknown, v: unknown) => { | ||
tinyassert(typeof k === "string"); | ||
tinyassert(Array.isArray(v)); | ||
res.setHeader(k, v); | ||
}; | ||
|
||
let error: unknown; | ||
await handleRequest(req2, res2, (e) => (error = e)); | ||
if (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.