import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; /** * Vite dev 配置 —— 统一端口 * * 浏览器只看到 :5173,所有 API / socket.io 都通过代理到内部 :8000: * /api/games → http://localhost:8000/games * /api/games/War/... → http://localhost:8000/games/War/... * /socket.io/ → http://localhost:8000/socket.io/ (ws upgrade) * * LAN 部署时只需要放行 :5173 这一个端口。 */ export default defineConfig({ plugins: [react()], server: { allowedHosts: ['playground.huajishe.fun'], port: 5173, strictPort: true, host: '0.0.0.0', // LAN 可达 proxy: { '/api': { target: 'http://localhost:8000', changeOrigin: true, // 不 rewrite:保留 /api,让 server 端的 mountApiPrefix 处理 // /api/games → http://localhost:8000/api/games → server 剥 /api → /games }, '/socket.io': { target: 'http://localhost:8000', ws: true, changeOrigin: true, }, }, }, build: { outDir: 'dist', sourcemap: true, }, });