44 lines
941 B
Markdown
44 lines
941 B
Markdown
# 前端代理到后端 (端口 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`)。
|