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 CSP_SEED_ADMIN_PASSWORD=whoami139
# 前端请求后端的地址(浏览器侧) # 前端请求后端的地址(浏览器侧)
NEXT_PUBLIC_API_BASE=http://localhost:8080 # 使用同域反代访问后端通过Next.js
NEXT_PUBLIC_API_BASE=/admin139
# Next.js 服务端反代用(可选) # Next.js 服务端反代用(可选)
BACKEND_INTERNAL_URL=http://backend:8080 BACKEND_INTERNAL_URL=http://backend:8080

查看文件

@@ -5,8 +5,9 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile.backend dockerfile: Dockerfile.backend
ports: # 如需直连后端调试,可打开端口映射;默认仅通过前端反代访问
- "8080:8080" # ports:
# - "8080:8080"
volumes: volumes:
- csp_data:/data - csp_data:/data
restart: unless-stopped restart: unless-stopped
@@ -18,8 +19,8 @@ services:
context: . context: .
dockerfile: Dockerfile.frontend dockerfile: Dockerfile.frontend
environment: environment:
# 浏览器侧请求后端的公共地址(本机测试用 localhost # 浏览器侧通过同域路径前缀访问后端Next.js反代到backend
- NEXT_PUBLIC_API_BASE=http://localhost:8080 - NEXT_PUBLIC_API_BASE=/admin139
# Next.js 服务端反代用(可选),仅在你把 NEXT_PUBLIC_API_BASE 设为 /api 时需要 # Next.js 服务端反代用(可选),仅在你把 NEXT_PUBLIC_API_BASE 设为 /api 时需要
- BACKEND_INTERNAL_URL=http://backend:8080 - BACKEND_INTERNAL_URL=http://backend:8080
ports: 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
- 后端通过前端反代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 // For local dev convenience. In production you should configure reverse proxy
// and set NEXT_PUBLIC_API_BASE to your public API origin. // and set NEXT_PUBLIC_API_BASE to your public API origin.
async rewrites() { async rewrites() {
// If the user sets NEXT_PUBLIC_API_BASE to "/api", we can proxy to backend // Reverse proxy backend under a path prefix, so browser can access backend
// from the Next.js server (SSR). This does NOT affect browser fetch. // with same-origin (no CORS): http://<host>:7888/admin139/...
const backendInternal = process.env.BACKEND_INTERNAL_URL; const backendInternal = process.env.BACKEND_INTERNAL_URL;
if (!backendInternal) return []; if (!backendInternal) return [];
return [ return [
{ {
source: "/api/:path*", source: "/admin139/:path*",
destination: `${backendInternal}/api/:path*`, destination: `${backendInternal}/:path*`,
}, },
]; ];
}, },