diff --git a/web/.env.example b/web/.env.example index 2c5cdb153..f954e347f 100644 --- a/web/.env.example +++ b/web/.env.example @@ -1 +1,5 @@ -VITE_API_BASE_URL=http://localhost:5300 +# Leave empty in development to use Vite's same-origin proxy. This keeps API, +# login, and WebSocket requests working when the UI is opened from another +# device on the local network. +VITE_API_BASE_URL= +VITE_API_PROXY_TARGET=http://127.0.0.1:5300 diff --git a/web/vite.config.ts b/web/vite.config.ts index d1023070a..d2899a62f 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,18 +1,35 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; import path from 'path'; -export default defineConfig({ - plugins: [react()], - resolve: { - alias: { - '@': path.resolve(__dirname, './src'), +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ''); + const apiProxyTarget = env.VITE_API_PROXY_TARGET || 'http://127.0.0.1:5300'; + + return { + plugins: [react()], + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, }, - }, - server: { - port: 3000, - }, - build: { - outDir: 'dist', - }, + server: { + host: '0.0.0.0', + port: 3000, + proxy: { + '/api': { + target: apiProxyTarget, + changeOrigin: true, + ws: true, + }, + '/mcp': { + target: apiProxyTarget, + changeOrigin: true, + }, + }, + }, + build: { + outDir: 'dist', + }, + }; });