hyf-backend/scripts/FRONTEND_PROXY.md

941 B
Raw Blame History

前端代理到后端 (端口 5005 → 8000)

前端(如运行在 5005 的 Vite/Vben访问 /api/* 时,需要转发到本后端 http://localhost:8000

Vite

vite.config.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(同上)。

直接调后端(排错用)

不经过前端代理,直接请求后端:

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)。