Add single domain gateway routing

This commit is contained in:
2026-07-09 16:03:29 +08:00
parent 664d1acbce
commit 7587da6d18
14 changed files with 133 additions and 29 deletions

View File

@@ -13,8 +13,9 @@ FEISHU_SEARCH_URL=
FRP_SERVER_ADDR=your-server-ip
FRP_SERVER_PORT=7000
FRP_AUTH_TOKEN=your-auth-token
FRP_PROXY_NAME=qa-backend
# 映射到后端端口 8100
FRP_LOCAL_PORT=8100
# 自定义域名逗号分隔qa.yourdomain.com,your-server-ip
FRP_CUSTOM_DOMAINS=qa.yourdomain.com,your-server-ip
FRP_PROXY_NAME=qa-web
# 默认穿透统一入口 gateway:80由 gateway 按路径转发到用户端、后台和 API
FRP_LOCAL_IP=gateway
FRP_LOCAL_PORT=80
# 自定义域名逗号分隔qa.huiyushuyuan.cn
FRP_CUSTOM_DOMAINS=qa.huiyushuyuan.cn

View File

@@ -39,9 +39,13 @@ docker compose -f docker-compose.dev.yml up --build
默认访问地址:
- 用户端 H5`http://127.0.0.1:5173/`
- 管理后台`http://127.0.0.1:5174/`
- 后端 API`http://127.0.0.1:8100/api/health`
- 统一入口`http://127.0.0.1:8080/`
- 用户端 H5`http://127.0.0.1:8080/`
- 管理后台`http://127.0.0.1:8080/login`
- 后端 API`http://127.0.0.1:8080/api/health`
- 用户端直连调试:`http://127.0.0.1:5173/`
- 管理后台直连调试:`http://127.0.0.1:5174/login/`
- 后端直连调试:`http://127.0.0.1:8100/api/health`
- MySQL`127.0.0.1:3307`
开发阶段 mock 短信验证码为 `123456`

View File

@@ -1 +1 @@
VITE_API_BASE_URL=http://127.0.0.1:8100/api
VITE_API_BASE_URL=/api

View File

@@ -12,13 +12,13 @@ npm run dev -- --port 5174
默认访问地址:
```text
http://127.0.0.1:5174/
http://127.0.0.1:8080/login
```
默认后端地址:
```text
http://127.0.0.1:8100/api
/api
```
## 默认管理员

View File

@@ -14,7 +14,7 @@ import type {
UserImportResult,
} from "../types/api";
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? "http://127.0.0.1:8100/api";
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? "/api";
const TOKEN_KEY = "ai-kb-admin-token";
export function getToken() {

View File

@@ -2,6 +2,7 @@ import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
base: "/login/",
plugins: [vue()],
build: {
rollupOptions: {

View File

@@ -1 +1 @@
VITE_API_BASE_URL=http://127.0.0.1:8100/api
VITE_API_BASE_URL=/api

View File

@@ -33,7 +33,11 @@ npm run dev
默认 API 地址为:
`http://127.0.0.1:8100/api`
`/api`
统一入口访问地址为:
`http://127.0.0.1:8080/`
## 说明

View File

@@ -1,6 +1,6 @@
import type { ApiResponse, CaptchaResult, ChatMessage, ChatSession, LoginResult, UserProfile } from "../types/api";
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? "http://127.0.0.1:8100/api";
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? "/api";
const TOKEN_KEY = "ai-kb-user-token";
export function getToken() {

View File

@@ -23,14 +23,14 @@ serverPort = ${FRP_SERVER_PORT:-7000}
auth.token = "${FRP_AUTH_TOKEN}"
[[proxies]]
name = "${FRP_PROXY_NAME:-qa-backend}"
name = "${FRP_PROXY_NAME:-qa-web}"
type = "http"
localIP = "${FRP_LOCAL_IP:-backend}"
localPort = ${FRP_LOCAL_PORT:-8100}
localIP = "${FRP_LOCAL_IP:-gateway}"
localPort = ${FRP_LOCAL_PORT:-80}
customDomains = [${_domains}]
EOF
echo "=== frpc config generated ==="
cat /etc/frp/frpc.toml
exec frpc -c /etc/frp/frpc.toml
exec frpc -c /etc/frp/frpc.toml

View File

@@ -0,0 +1,54 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name _;
client_max_body_size 20m;
location = /login {
return 302 $scheme://$http_host/login/;
}
location ^~ /api/ {
proxy_pass http://backend:8100;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_buffering off;
proxy_read_timeout 3600s;
}
location ^~ /login/ {
proxy_pass http://admin-web:5174;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_buffering off;
proxy_read_timeout 3600s;
}
location / {
proxy_pass http://user-client:5173;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_buffering off;
proxy_read_timeout 3600s;
}
}

View File

@@ -42,11 +42,34 @@ docker compose -f docker-compose.dev.yml up -d --build backend user-client admin
默认地址:
- 用户端 H5`http://127.0.0.1:5173/`
- 管理后台`http://127.0.0.1:5174/`
- 后端健康检查`http://127.0.0.1:8100/api/health`
- 统一入口`http://127.0.0.1:8080/`
- 用户端 H5`http://127.0.0.1:8080/`
- 管理后台`http://127.0.0.1:8080/login`
- 后端健康检查:`http://127.0.0.1:8080/api/health`
- 用户端直连调试:`http://127.0.0.1:5173/`
- 管理后台直连调试:`http://127.0.0.1:5174/login/`
- 后端直连调试:`http://127.0.0.1:8100/api/health`
- MySQL`127.0.0.1:3307`
## 单域名访问
当前编排新增 `gateway` 服务作为统一入口。内网穿透时建议只穿透 `gateway:80`,域名路径分流如下:
```text
https://qa.huiyushuyuan.cn/ 用户端 H5
https://qa.huiyushuyuan.cn/login 管理后台登录页
https://qa.huiyushuyuan.cn/api/... 后端 API
```
`.env` 中推荐配置:
```bash
FRP_PROXY_NAME=qa-web
FRP_LOCAL_IP=gateway
FRP_LOCAL_PORT=80
FRP_CUSTOM_DOMAINS=qa.huiyushuyuan.cn
```
## 开发阶段默认账号
用户端:

View File

@@ -9,7 +9,9 @@
- [ ] 已替换 `JWT_SECRET_KEY`
- [ ] 已确认飞书检索配置。
- [ ] 已确认模型配置和额度策略。
- [ ] 已确认前端 API 地址
- [ ] 已确认统一入口 `gateway` 可访问
- [ ] 已确认前端 API 地址使用同域 `/api`
- [ ] 已确认内网穿透指向 `gateway:80`
## 发布中
@@ -18,11 +20,14 @@
- [ ] 启动后端服务。
- [ ] 启动用户端 H5。
- [ ] 启动管理后台。
- [ ] 检查后端健康接口
- [ ] 启动统一入口 gateway
- [ ] 检查 `域名/api/health` 后端健康接口。
## 发布后
- [ ] 用户端可以登录。
- [ ] 默认打开域名进入用户端。
- [ ] `域名/login` 进入管理后台登录页。
- [ ] 用户端可以创建会话。
- [ ] 用户端可以提问并收到回答。
- [ ] 无命中问题返回固定兜底。

View File

@@ -72,7 +72,7 @@ services:
context: ./apps/user-client
container_name: ai_kb_v2_user_client
environment:
VITE_API_BASE_URL: http://127.0.0.1:8100/api
VITE_API_BASE_URL: /api
ports:
- "5173:5173"
depends_on:
@@ -83,12 +83,24 @@ services:
context: ./apps/admin-web
container_name: ai_kb_v2_admin_web
environment:
VITE_API_BASE_URL: http://127.0.0.1:8100/api
VITE_API_BASE_URL: /api
ports:
- "5174:5174"
depends_on:
- backend
gateway:
image: nginx:1.27-alpine
container_name: ai_kb_v2_gateway
ports:
- "8080:80"
volumes:
- ./deploy/gateway.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- backend
- user-client
- admin-web
frpc:
build:
context: .
@@ -99,11 +111,11 @@ services:
FRP_SERVER_PORT: ${FRP_SERVER_PORT:-7000}
FRP_AUTH_TOKEN: ${FRP_AUTH_TOKEN}
FRP_PROXY_NAME: ${FRP_PROXY_NAME:-qa-backend}
FRP_LOCAL_IP: ${FRP_LOCAL_IP:-backend}
FRP_LOCAL_PORT: ${FRP_LOCAL_PORT:-8100}
FRP_LOCAL_IP: ${FRP_LOCAL_IP:-gateway}
FRP_LOCAL_PORT: ${FRP_LOCAL_PORT:-80}
FRP_CUSTOM_DOMAINS: ${FRP_CUSTOM_DOMAINS}
depends_on:
- backend
- gateway
restart: unless-stopped
volumes: