Files
KCGL/inventory-web/vite.config.ts

30 lines
1.0 KiB
TypeScript
Raw 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.

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
// 【关键修改1】必须设置为 0.0.0.0,否则容器外无法访问
host: '0.0.0.0',
// 【关键修改2】显式指定端口与 docker-compose 映射保持一致
port: 5173,
proxy: {
'/api': {
// 【关键修改3】
// 1. 'backend' 是 docker-compose.yml 里的服务名
// 2. 端口改为 8000 (Gunicorn 配置的端口)
target: 'http://backend:8000',
changeOrigin: true,
// 注意:如果你的 Flask 路由代码里没有写 /api 前缀(例如 @app.route('/login')
// 那么你需要取消下面这行的注释,把 /api 去掉,否则后端会收到 /api/login 报 404
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})