From bab7664b5edf3a44b6ed2749c3d457568cfc4c79 Mon Sep 17 00:00:00 2001 From: shenlan Date: Sun, 3 Aug 2025 08:26:43 +0800 Subject: [PATCH] feat(ui): proxy API calls and allow configurable endpoint --- ui/homepage/components/AskAIDialog.tsx | 3 ++- ui/homepage/next.config.js | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ui/homepage/components/AskAIDialog.tsx b/ui/homepage/components/AskAIDialog.tsx index e640870..3d7d298 100644 --- a/ui/homepage/components/AskAIDialog.tsx +++ b/ui/homepage/components/AskAIDialog.tsx @@ -11,7 +11,8 @@ export function AskAIDialog({ open, onClose }: { open: boolean; onClose: () => v async function handleAsk() { if (!question) return const userMessage = { sender: 'user' as const, text: question } - const res = await fetch('/api/askai', { + const apiBase = process.env.NEXT_PUBLIC_API_BASE_URL || '' + const res = await fetch(`${apiBase}/api/askai`, { method: 'POST', body: JSON.stringify({ question, history: messages }), }) diff --git a/ui/homepage/next.config.js b/ui/homepage/next.config.js index d487aa9..ec42c38 100644 --- a/ui/homepage/next.config.js +++ b/ui/homepage/next.config.js @@ -1,11 +1,16 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - output: 'export', // 开启静态导出 + output: 'export', // 静态导出 reactStrictMode: true, - // 移除 experimental.appDir - // experimental: { - // appDir: true - // } + + async rewrites() { + return [ + { + source: '/api/:path*', + destination: 'http://localhost:3002/api/:path*', // 后端服务 + }, + ] + }, } module.exports = nextConfig