diff --git a/lib/eden.ts b/lib/eden.ts index 39435ac..30c5107 100644 --- a/lib/eden.ts +++ b/lib/eden.ts @@ -1,7 +1,10 @@ import { treaty } from "@elysia/eden" -import { app } from "@/app/api/[[...slugs]]/route" +import type { App } from "@/app/api/[[...slugs]]/route" +// Use require() on the server branch to prevent the client bundler from +// pulling in Elysia and the route module. The typeof window check is the +// standard Next.js server-vs-client guard. export const api = - typeof process !== "undefined" - ? treaty(app).api - : treaty("localhost:3000").api + typeof window === "undefined" + ? treaty((require("../../app/api/[[...slugs]]/route") as { app: App }).app).api + : treaty(process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000").api