fix: resolve AsyncLocalStorage + dir issues in custom server, update benchmark script

Co-authored-by: ajnart <49837342+ajnart@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andajnart committed 2026-02-28 09:13:41 +00:00
1 parent c8ae7f283a
commit 8994bdedc3
3 files changed
+120 -80

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"build": "pnpm with-env next build && pnpm build:custom-server",
"build:custom-server": "esbuild server.ts --bundle --platform=node --outfile=customServer.cjs --external:bcrypt --external:@opentelemetry/api --external:deasync --external:cpu-features --loader:.html=text --loader:.scss=text --loader:.node=text",
"build:custom-server": "esbuild server.ts --bundle --platform=node --outfile=customServer.cjs --external:next --external:bcrypt --external:@opentelemetry/api --external:deasync --external:cpu-features --loader:.html=text --loader:.scss=text --loader:.node=text",
"clean": "git clean -xdf .next .turbo node_modules",
"dev": "pnpm with-env tsx ./server.ts",
"format": "prettier --check . --ignore-path ../../.gitignore",
+7 -1
View File
@@ -1,4 +1,8 @@
// Must be imported first to set up globalThis.AsyncLocalStorage for Next.js
import "next/dist/server/node-environment-baseline";
import { createServer } from "http";
import path from "path";
import next from "next";
import { parse } from "url";
import { applyWSSHandler } from "@trpc/server/adapters/ws";
@@ -15,8 +19,10 @@ const logger = createLogger({ module: "customServer" });
const dev = process.env.NODE_ENV !== "production";
const hostname = process.env.HOSTNAME || "localhost";
const port = parseInt(process.env.PORT || "3000", 10);
// Resolve the directory of this file so Next.js can find the app/pages dirs
const dir = path.resolve(__dirname);
const app = next({ dev, hostname, port });
const app = next({ dev, hostname, port, dir });
const handle = app.getRequestHandler();
app.prepare().then(() => {