chore(proxy): expose backend under /admin139 on frontend port
这个提交包含在:
3
.env
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*`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户