hyf-backend/scripts/FRONTEND_PROXY.md

44 lines
941 B
Markdown
Raw Normal View History

2026-01-21 13:45:39 +08:00
# 前端代理到后端 (端口 5005 → 8000)
前端(如运行在 5005 的 Vite/Vben访问 `/api/*` 时,需要转发到本后端 **http://localhost:8000**
## Vite
`vite.config.ts` 中:
```ts
export default defineConfig({
server: {
port: 5005,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
},
},
},
});
```
## Vben Admin
`.env.development` 或环境变量中设置:
```
VITE_GLOB_API_URL=/api
```
并确保 Vite 的 `server.proxy``/api` 指向 `http://localhost:8000`(同上)。
## 直接调后端(排错用)
不经过前端代理,直接请求后端:
```bash
curl -X POST 'http://localhost:8000/api/auth/login' \
-H 'Content-Type: application/json' \
-d '{"email":"admin@example.com","password":"admin123"}'
```
默认管理员:`admin@example.com` / `admin123`(需先执行 `python3 scripts/seed_admin.py`)。