瀏覽代碼

Fix API paths for /chat/ base URL deployment

Use import.meta.env.BASE_URL (resolves to /chat/ in production) for:
- tRPC client URL: /api/trpc → BASE_URL + api/trpc
- Login redirect: /login → BASE_URL + login
- OAuth callback redirectUri: /api/oauth/callback → BASE_URL + api/oauth/callback

Without this fix, API requests went to Tomcat instead of Node.js.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tony T 2 周之前
父節點
當前提交
e2b8ee3abd
共有 2 個文件被更改,包括 3 次插入3 次删除
  1. 1 1
      client/src/const.ts
  2. 2 2
      client/src/main.tsx

+ 1 - 1
client/src/const.ts

@@ -4,7 +4,7 @@ export { COOKIE_NAME, ONE_YEAR_MS } from "@shared/const";
 export const getLoginUrl = (returnPath?: string) => {
   const oauthPortalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL;
   const appId = import.meta.env.VITE_APP_ID;
-  const redirectUri = `${window.location.origin}/api/oauth/callback`;
+  const redirectUri = `${window.location.origin}${import.meta.env.BASE_URL}api/oauth/callback`;
   // Encode both the redirect URI and optional return path in state
   const statePayload = returnPath
     ? JSON.stringify({ redirectUri, returnPath })

+ 2 - 2
client/src/main.tsx

@@ -20,7 +20,7 @@ const redirectToLoginIfUnauthorized = (error: unknown) => {
 
   // Redirect to our custom login page instead of OAuth
   const currentPath = window.location.pathname;
-  window.location.href = `/login?returnTo=${encodeURIComponent(currentPath)}`;
+  window.location.href = `${import.meta.env.BASE_URL}login?returnTo=${encodeURIComponent(currentPath)}`;
 };
 
 queryClient.getQueryCache().subscribe(event => {
@@ -42,7 +42,7 @@ queryClient.getMutationCache().subscribe(event => {
 const trpcClient = trpc.createClient({
   links: [
     httpBatchLink({
-      url: "/api/trpc",
+      url: `${import.meta.env.BASE_URL}api/trpc`,
       transformer: superjson,
       fetch(input, init) {
         return globalThis.fetch(input, {