chore(proxy): expose backend under /admin139 on frontend port

这个提交包含在:
anygen-build-bot
2026-02-12 10:40:23 +00:00
父节点 21a5c0f269
当前提交 d33deed4c5
修改 4 个文件,包含 14 行新增12 行删除

3
.env
查看文件

@@ -10,7 +10,8 @@ CSP_SEED_ADMIN_USERNAME=admin
CSP_SEED_ADMIN_PASSWORD=whoami139
# 前端请求后端的地址(浏览器侧)
NEXT_PUBLIC_API_BASE=http://localhost:8080
# 使用同域反代访问后端通过Next.js
NEXT_PUBLIC_API_BASE=/admin139
# Next.js 服务端反代用(可选)
BACKEND_INTERNAL_URL=http://backend:8080

查看文件

@@ -5,8 +5,9 @@ services:
build:
context: .
dockerfile: Dockerfile.backend
ports:
- "8080:8080"
# 如需直连后端调试,可打开端口映射;默认仅通过前端反代访问
# ports:
# - "8080:8080"
volumes:
- csp_data:/data
restart: unless-stopped
@@ -18,8 +19,8 @@ services:
context: .
dockerfile: Dockerfile.frontend
environment:
# 浏览器侧请求后端的公共地址(本机测试用 localhost
- NEXT_PUBLIC_API_BASE=http://localhost:8080
# 浏览器侧通过同域路径前缀访问后端Next.js反代到backend
- NEXT_PUBLIC_API_BASE=/admin139
# Next.js 服务端反代用(可选),仅在你把 NEXT_PUBLIC_API_BASE 设为 /api 时需要
- BACKEND_INTERNAL_URL=http://backend:8080
ports:

查看文件

@@ -8,10 +8,10 @@ docker compose up -d --build
## 访问
- 后端健康检查http://localhost:8080/api/health
- 后端(注册):`POST http://localhost:8080/api/v1/auth/register`
- 后端(登录):`POST http://localhost:8080/api/v1/auth/login`
- 前端http://localhost:7888
- 后端通过前端反代http://localhost:7888/admin139/api/health
- 后端(注册):`POST http://localhost:7888/admin139/api/v1/auth/register`
- 后端(登录):`POST http://localhost:7888/admin139/api/v1/auth/login`
## 数据持久化

查看文件

@@ -4,15 +4,15 @@ const nextConfig: NextConfig = {
// For local dev convenience. In production you should configure reverse proxy
// and set NEXT_PUBLIC_API_BASE to your public API origin.
async rewrites() {
// If the user sets NEXT_PUBLIC_API_BASE to "/api", we can proxy to backend
// from the Next.js server (SSR). This does NOT affect browser fetch.
// Reverse proxy backend under a path prefix, so browser can access backend
// with same-origin (no CORS): http://<host>:7888/admin139/...
const backendInternal = process.env.BACKEND_INTERNAL_URL;
if (!backendInternal) return [];
return [
{
source: "/api/:path*",
destination: `${backendInternal}/api/:path*`,
source: "/admin139/:path*",
destination: `${backendInternal}/:path*`,
},
];
},