From 779a5bffe74e0e7ea5e94a1d7a5d269f2c28b79c Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 11 Nov 2025 06:34:02 +0000 Subject: [PATCH] completionId: cgen-db532f6e1d6b4772914ad076e32f23db cgen-db532f6e1d6b4772914ad076e32f23db --- server/index.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/index.ts b/server/index.ts index b72a1579..600b665e 100644 --- a/server/index.ts +++ b/server/index.ts @@ -751,12 +751,21 @@ export function createServer() { .json({ error: "Discord client ID not configured" }); } - // Get the current API base from the request origin - const protocol = - req.headers["x-forwarded-proto"] || req.protocol || "https"; - const host = - req.headers["x-forwarded-host"] || req.hostname || req.get("host"); - const apiBase = `${protocol}://${host}`; + // Use the API base URL (should match Discord Dev Portal redirect URI) + let apiBase = + process.env.VITE_API_BASE || + process.env.API_BASE || + process.env.PUBLIC_BASE_URL || + process.env.SITE_URL; + + if (!apiBase) { + // Fallback to request origin if no env var is set + const protocol = + req.headers["x-forwarded-proto"] || req.protocol || "https"; + const host = + req.headers["x-forwarded-host"] || req.hostname || req.get("host"); + apiBase = `${protocol}://${host}`; + } const redirectUri = `${apiBase}/api/discord/oauth/callback`;