- 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
27 lines
656 B
TypeScript
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
|
|
}
|