Ali Azlan
Ali Azlan
HHono
Created by Ali Azlan on 5/26/2024 in #help
Node.js does not work in Next.js
Following is my api/[[...route]]/route.ts file
import { Hono } from "hono";
import links from "./links";
import auth from "./auth";
import { HTTPException } from "hono/http-exception";
import { handle } from "@hono/node-server/vercel";
import type { PageConfig } from "next";

export const config: PageConfig = {
api: {
bodyParser: false,
},
};

export const runtime = "nodejs";

const app = new Hono().basePath("/api");

app.onError((err, c) => {
if (err instanceof HTTPException) {
return err.getResponse();
}
return c.json({ message: "Internal Error" }, 500);
});

const routes = app
.route("/links", links)
.route("/auth", auth)

export const GET = handle(app);
export const POST = handle(app);

export type AppType = typeof routes;
import { Hono } from "hono";
import links from "./links";
import auth from "./auth";
import { HTTPException } from "hono/http-exception";
import { handle } from "@hono/node-server/vercel";
import type { PageConfig } from "next";

export const config: PageConfig = {
api: {
bodyParser: false,
},
};

export const runtime = "nodejs";

const app = new Hono().basePath("/api");

app.onError((err, c) => {
if (err instanceof HTTPException) {
return err.getResponse();
}
return c.json({ message: "Internal Error" }, 500);
});

const routes = app
.route("/links", links)
.route("/auth", auth)

export const GET = handle(app);
export const POST = handle(app);

export type AppType = typeof routes;
3 replies
HHono
Created by Ali Azlan on 5/26/2024 in #help
Node.js does not work in Next.js
at AsyncLocalStorage.run (node:async_hooks:346:14)
at e_.execute (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:44777)
at e_.handle (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:54711)
at doRender (node_modules/next/dist/server/base-server.js:1377:60)
at cacheEntry.responseCache.get.routeKind (node_modules/next/dist/server/base-server.js:1587:46)
at ResponseCache.get (node_modules/next/dist/server/response-cache/index.js:49:26)
at DevServer.renderToResponseWithComponentsImpl (node_modules/next/dist/server/base-server.js:1507:53)
at AsyncLocalStorage.run (node:async_hooks:346:14)
at e_.execute (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:44777)
at e_.handle (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:54711)
at doRender (node_modules/next/dist/server/base-server.js:1377:60)
at cacheEntry.responseCache.get.routeKind (node_modules/next/dist/server/base-server.js:1587:46)
at ResponseCache.get (node_modules/next/dist/server/response-cache/index.js:49:26)
at DevServer.renderToResponseWithComponentsImpl (node_modules/next/dist/server/base-server.js:1507:53)
3 replies