Files
otunes/apps/web/lib/convex-server.ts
T
joshuafhiggins Verified 1cea1fe745 feat(docker): bundle Convex backend with oTunes
- Run the web app and Convex backend in one container with generated per-install keys
- Derive Convex URLs from the server address and update self-hosting docs
2026-10-08 15:24:00 -04:00

27 lines
656 B
TypeScript

import { ConvexHttpClient } from "convex/browser"
let client: ConvexHttpClient | null = null
/**
* URL the Next.js server uses to reach Convex. Never derive this from request
* headers: auth tokens are sent to it, so a forged Host would leak them.
*/
export function getConvexServerUrl() {
return (
process.env.CONVEX_INTERNAL_URL ??
process.env.NEXT_PUBLIC_CONVEX_URL ??
"http://127.0.0.1:3210"
)
}
export function convexServerOptions(token?: string) {
return { url: getConvexServerUrl(), token }
}
export function getConvexClient() {
if (!client) {
client = new ConvexHttpClient(getConvexServerUrl())
}
return client
}