mirror of
https://github.com/2930134478/AI-CS.git
synced 2026-06-15 00:44:30 +08:00
修复配置项冲突错误
This commit is contained in:
+1
-2
@@ -34,8 +34,7 @@ ENCRYPTION_KEY=changeme_please_use_random_hex_32_bytes_here
|
||||
# 前端服务配置
|
||||
# ============================================
|
||||
FRONTEND_PORT=3000
|
||||
# 前端访问后端的地址(Docker 内部使用容器名,外部访问使用 localhost)
|
||||
NEXT_PUBLIC_API_BASE_URL=http://localhost:8080
|
||||
|
||||
|
||||
# ============================================
|
||||
# 生产版镜像配置(仅用于 docker-compose.prod.yml)
|
||||
|
||||
@@ -304,16 +304,6 @@ ENCRYPTION_KEY=your_32_byte_key # 使用 openssl rand -hex 32 生成
|
||||
- `ADMIN_PASSWORD` 是必填项,如果不设置,系统不会创建默认管理员账号
|
||||
- 生产环境请使用强密码并设置 `GIN_MODE=release`
|
||||
|
||||
### 前端环境变量(可选)
|
||||
|
||||
在 `frontend/.env.local` 中配置(不配置则使用默认值):
|
||||
|
||||
```env
|
||||
NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
> 本地开发无需配置,已默认 `http://127.0.0.1:8080`。生产环境请修改为实际后端地址。
|
||||
|
||||
## 🔌 集成客服插件到你的网站
|
||||
|
||||
#### 步骤 1:在 HTML 中添加代码
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
// 统一的 API 配置
|
||||
// 读取 NEXT_PUBLIC_ 开头的环境变量(Next.js 会自动暴露到浏览器)
|
||||
// 使用默认值方便本地开发
|
||||
//
|
||||
// 配置方式:
|
||||
// 1. 创建 frontend/.env.local 文件(推荐)
|
||||
// 2. 添加:NEXT_PUBLIC_API_BASE_URL=http://你的IP:8080
|
||||
// 3. 重启前端服务
|
||||
//
|
||||
// 示例(局域网访问,允许手机/平板访问):
|
||||
// NEXT_PUBLIC_API_BASE_URL=http://192.168.124.9:8080
|
||||
//
|
||||
// 本地开发(仅本机访问):
|
||||
// NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8080
|
||||
export const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:8080";
|
||||
// 使用相对路径,自动适配当前域名(无论是否绑定域名都能工作)
|
||||
// 前端和后端通过 Nginx 代理在同一域名下,所以使用相对路径即可
|
||||
export const API_BASE_URL = '';
|
||||
|
||||
|
||||
@@ -49,12 +49,11 @@ export class WSClient<T = unknown> {
|
||||
this.ws = null;
|
||||
}
|
||||
|
||||
// 获取 API 基地址
|
||||
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:8080";
|
||||
// 将 http:// 替换为 ws://,将 https:// 替换为 wss://
|
||||
let wsUrl =
|
||||
apiBaseUrl.replace(/^http/, "ws") +
|
||||
`/ws?conversation_id=${this.conversationId}&is_visitor=${this.isVisitor}`;
|
||||
// 使用相对路径构建 WebSocket URL(自动适配当前域名和协议)
|
||||
// 根据当前页面的协议自动选择 ws:// 或 wss://
|
||||
const protocol = typeof window !== 'undefined' && window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const host = typeof window !== 'undefined' ? window.location.host : '';
|
||||
let wsUrl = `${protocol}//${host}/ws?conversation_id=${this.conversationId}&is_visitor=${this.isVisitor}`;
|
||||
// 如果是客服连接,添加 agent_id 参数
|
||||
if (!this.isVisitor && this.agentId) {
|
||||
wsUrl += `&agent_id=${this.agentId}`;
|
||||
|
||||
Reference in New Issue
Block a user