diff --git a/vite.config.mts b/vite.config.mts index a52e4c81c..12ad46362 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -17,10 +17,21 @@ const SHOULD_MINIFY = process.env.ENABLE_MINIFY === 'true' // vite dev server will listen on all addresses, including LAN and public addresses const VITE_REMOTE_DEV = process.env.VITE_REMOTE_DEV === 'true' const DISABLE_TEMPLATES_PROXY = process.env.DISABLE_TEMPLATES_PROXY === 'true' -const DISABLE_VUE_PLUGINS = process.env.DISABLE_VUE_PLUGINS === 'true' +const DISABLE_VUE_PLUGINS = false // Always enable Vue DevTools for development -const DEV_SERVER_COMFYUI_URL = - process.env.DEV_SERVER_COMFYUI_URL || 'http://127.0.0.1:8188' +// Hardcoded to staging cloud for testing frontend changes against cloud backend +const DEV_SERVER_COMFYUI_URL = 'https://stagingcloud.comfy.org' +// To use local backend, change to: 'http://127.0.0.1:8188' + +// Optional: Add API key to .env as STAGING_API_KEY if needed for authentication +const addAuthHeaders = (proxy: any) => { + proxy.on('proxyReq', (proxyReq: any, _req: any, _res: any) => { + const apiKey = process.env.STAGING_API_KEY + if (apiKey) { + proxyReq.setHeader('X-API-KEY', apiKey) + } + }) +} export default defineConfig({ base: '', @@ -28,16 +39,31 @@ export default defineConfig({ host: VITE_REMOTE_DEV ? '0.0.0.0' : undefined, proxy: { '/internal': { - target: DEV_SERVER_COMFYUI_URL + target: DEV_SERVER_COMFYUI_URL, + changeOrigin: true, + secure: false, + configure: addAuthHeaders }, '/api': { target: DEV_SERVER_COMFYUI_URL, + changeOrigin: true, + secure: false, + configure: (proxy, _options) => { + addAuthHeaders(proxy) + }, // Return empty array for extensions API as these modules // are not on vite's dev server. bypass: (req, res, _options) => { if (req.url === '/api/extensions') { res.end(JSON.stringify([])) + return false // Return false to indicate request is handled + } + // Bypass multi-user auth check from staging + if (req.url === '/api/users') { + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify({})) // Return empty object to simulate single-user mode + return false // Return false to indicate request is handled } return null } @@ -45,29 +71,39 @@ export default defineConfig({ '/ws': { target: DEV_SERVER_COMFYUI_URL, - ws: true + ws: true, + changeOrigin: true, + secure: false, + configure: addAuthHeaders }, '/workflow_templates': { - target: DEV_SERVER_COMFYUI_URL + target: DEV_SERVER_COMFYUI_URL, + changeOrigin: true, + secure: false, + configure: addAuthHeaders }, // Proxy extension assets (images/videos) under /extensions to the ComfyUI backend '/extensions': { target: DEV_SERVER_COMFYUI_URL, - changeOrigin: true + changeOrigin: true, + secure: false }, // Proxy docs markdown from backend '/docs': { target: DEV_SERVER_COMFYUI_URL, - changeOrigin: true + changeOrigin: true, + secure: false }, ...(!DISABLE_TEMPLATES_PROXY ? { '/templates': { - target: DEV_SERVER_COMFYUI_URL + target: DEV_SERVER_COMFYUI_URL, + changeOrigin: true, + secure: false } } : {}),