ZX
ZX
Explore posts from servers
HHono
Created by ZX on 6/12/2024 in #help
Experimenting with custom NextJS Server
Hey guys, I'm running into an issue where nextjs is not hydrating properly and hono is giving an error: unhandledRejection: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client Here's the code:
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();
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();
I'm wondering if anyone with more experience or insight might have an idea with what's going wrong here
2 replies