fix(eden): resolve server/client detection and bundler issues
- Use typeof window === undefined for standard Next.js server detection - Use NEXT_PUBLIC_SITE_URL env var instead of hardcoded localhost:3000 - Use require() for server branch to prevent Elysia from entering client bundle - Add type assertion on require() to preserve Eden Treaty types
This commit is contained in:
+7
-4
@@ -1,7 +1,10 @@
|
|||||||
import { treaty } from "@elysia/eden"
|
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 =
|
export const api =
|
||||||
typeof process !== "undefined"
|
typeof window === "undefined"
|
||||||
? treaty(app).api
|
? treaty((require("../../app/api/[[...slugs]]/route") as { app: App }).app).api
|
||||||
: treaty<typeof app>("localhost:3000").api
|
: treaty<App>(process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000").api
|
||||||
|
|||||||
Reference in New Issue
Block a user