chore: update dev setup to use docker compose backend
Default backend URL changed from port 8080 (kubectl port-forward) to 18080 (docker compose Envoy Gateway). README updated to reflect the deploy/dev workflow.
This commit is contained in:
@@ -29,27 +29,21 @@ pnpm install
|
||||
|
||||
1. **启动后端服务**
|
||||
|
||||
后端使用 Kubernetes 部署,需要先启动后端集群(参考后端仓库的部署文档)。
|
||||
|
||||
2. **配置端口转发**
|
||||
|
||||
将后端 Envoy Gateway 转发到本地:
|
||||
在后端仓库的 `deploy/dev` 目录下构建并启动所有微服务:
|
||||
|
||||
```bash
|
||||
kubectl port-forward -n juwan svc/envoy-gateway 8080:80
|
||||
cd ../juwan-backend/deploy/dev
|
||||
python3 build.py
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
3. **配置环境变量**
|
||||
|
||||
创建 `.env.local` 文件:
|
||||
验证后端是否正常运行:
|
||||
|
||||
```bash
|
||||
# 后端 API 地址(通过 kubectl port-forward 转发)
|
||||
NEXT_PUBLIC_BACKEND_URL=http://localhost:8080
|
||||
|
||||
curl http://127.0.0.1:18080/healthz
|
||||
```
|
||||
|
||||
4. **启动前端开发服务器**
|
||||
2. **启动前端开发服务器**
|
||||
|
||||
```bash
|
||||
pnpm dev
|
||||
@@ -57,11 +51,7 @@ pnpm install
|
||||
|
||||
访问 http://localhost:3000
|
||||
|
||||
**工作原理**:
|
||||
- 前端向 `/api/*` 发起请求
|
||||
- Next.js dev server 自动将请求代理到 `http://localhost:8080/api/*`
|
||||
- 后端通过 `kubectl port-forward` 接收请求
|
||||
- 无需修改前端代码中的 API 调用路径
|
||||
Next.js 会自动将 `/api/*` 请求代理到 `http://localhost:18080/api/*`(后端 Envoy Gateway),无需额外配置。
|
||||
|
||||
### 其他命令
|
||||
|
||||
@@ -120,7 +110,7 @@ async rewrites() {
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
return []
|
||||
}
|
||||
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8080'
|
||||
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:18080'
|
||||
return [
|
||||
{
|
||||
source: '/api/:path*',
|
||||
@@ -141,7 +131,7 @@ async rewrites() {
|
||||
|
||||
| 变量名 | 说明 | 默认值 |
|
||||
| ------------------------- | ------------------------------- | ----------------------- |
|
||||
| `NEXT_PUBLIC_BACKEND_URL` | 后端 API 地址(仅开发环境生效) | `http://localhost:8080` |
|
||||
| `NEXT_PUBLIC_BACKEND_URL` | 后端 API 地址(仅开发环境生效) | `http://localhost:18080` |
|
||||
|
||||
**注意**:
|
||||
|
||||
@@ -176,15 +166,15 @@ kubectl apply -f deploy/k8s/frontend.yaml
|
||||
|
||||
### Q: 本地开发如何连后端?
|
||||
|
||||
A: 按照 开发环境设置 里的步骤完成 `kubectl port-forward`,并在 `.env.local` 配置 `NEXT_PUBLIC_BACKEND_URL`。前端统一请求 `/api/*`,开发环境由 Next.js 代理到本地转发端口。
|
||||
A: 在后端仓库 `deploy/dev` 下执行 `python3 build.py && docker compose up -d` 启动所有微服务,然后 `pnpm dev` 启动前端。默认代理到 `http://localhost:18080`,无需额外配置。
|
||||
|
||||
### Q: 后端连接失败怎么办?
|
||||
|
||||
A: 检查以下几点:
|
||||
|
||||
1. 后端 K8s 集群是否正常运行
|
||||
2. `kubectl port-forward` 是否在运行
|
||||
3. `.env.local` 中的 `NEXT_PUBLIC_BACKEND_URL` 是否正确
|
||||
1. 后端 Docker 容器是否正常运行(`docker compose ps`)
|
||||
2. Envoy Gateway 是否监听在 18080 端口(`curl http://127.0.0.1:18080/healthz`)
|
||||
3. 如果使用了自定义端口,检查 `.env.local` 中的 `NEXT_PUBLIC_BACKEND_URL`
|
||||
4. 浏览器控制台是否有 CORS 错误
|
||||
|
||||
### Q: 如何添加新的 API?
|
||||
|
||||
Reference in New Issue
Block a user