© 2026 Hedgehog Software, LLC
unhandledRejection: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
import { HttpBindings, getRequestListener } from "@hono/node-server"; import { Hono } from "hono"; import { createServer } from "http"; import { initialize } from "next/dist/server/lib/router-server"; const NODE_ENV = process.env.NODE_ENV! ?? "development"; const NODE_DEBUG = process.env.NODE_DEBUG!; const PORT = process.env.PORT! ?? "3000"; const HOSTNAME = process.env.HOSTNAME! ?? "localhost"; const EMPTY_BUFFER = Buffer.alloc(0); const app = new Hono<{ Bindings: HttpBindings }>(); const listener = getRequestListener(app.fetch); const main = async () => { const [handle, handleUpgrade] = await initialize({ dev: NODE_ENV !== "production", port: parseInt(PORT ?? "3000"), hostname: HOSTNAME, dir: process.cwd(), isNodeDebugging: NODE_DEBUG === "true", customServer: true, }); app.all("*", (c) => { if (c.env.incoming.headers.upgrade) { return handleUpgrade(c.env.incoming, c.env.incoming.socket, EMPTY_BUFFER); } return handle(c.env.incoming, c.env.outgoing); }); createServer(listener).listen(parseInt(PORT), () => { console.log(`Listening on port ${PORT}`); }); }; main();