hyf-backend/scripts/FRONTEND_PROXY.md

44 lines
941 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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