Files
vf_react/fix-cors-auth.sh
2025-11-22 09:27:12 +08:00

70 lines
1.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
echo "========================================="
echo "修复 CORS 和认证问题"
echo "========================================="
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 1. 修改环境配置 - 重要:通过域名访问,这样 Cookie 才能共享
echo "[1] 更新环境配置..."
cat > .env.local << 'EOF'
# 通过域名访问,避免跨域和 Cookie 问题
NEXT_PUBLIC_API_URL=https://valuefrontier.cn
NEXT_PUBLIC_MAIN_APP_URL=https://valuefrontier.cn
SESSION_COOKIE_NAME=session
PORT=3000
EOF
echo "✓ 环境配置已更新"
cat .env.local
# 2. 更新 Next.js 配置
echo ""
echo "[2] 更新 Next.js 配置..."
cat > next.config.js << 'EOF'
/** @type {import('next').NextConfig} */
const nextConfig = {
// 生产环境配置 basePath
basePath: process.env.NODE_ENV === 'production' ? '/ai-chat' : '',
assetPrefix: process.env.NODE_ENV === 'production' ? '/ai-chat' : '',
reactStrictMode: true,
poweredByHeader: false,
outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk',
// API 重写 - 开发环境使用
async rewrites() {
// 生产环境不需要重写,直接通过域名访问
if (process.env.NODE_ENV === 'production') {
return [];
}
return [
{
source: '/api/:path*',
destination: 'http://localhost:5001/api/:path*',
},
{
source: '/mcp/:path*',
destination: 'http://localhost:8900/:path*',
},
];
},
images: {
domains: ['valuefrontier.cn', 'localhost', '49.232.185.254'],
},
};
module.exports = nextConfig;
EOF
echo "✓ Next.js 配置已更新"
echo ""
echo "========================================="
echo "请重启 Next.js"
echo "1. 按 Ctrl+C 停止当前服务"
echo "2. 运行: npm run dev"
echo "========================================="