mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-26 17:30:07 +00:00
refactor(vite.config): simplify cloud config (#6211)
## Summary Simplify the `vite.config.mts` now that we know `addAuthHeaders` is not necessary. ## Changes - remove `addAuthHeaders` - simplify cloud configuration objects accordingly. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6211-refactor-vite-config-simplify-cloud-config-2956d73d365081659cfade4e289a872f) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -27,8 +27,14 @@ const GENERATE_SOURCEMAP = process.env.GENERATE_SOURCEMAP !== 'false'
|
|||||||
const DEV_SERVER_COMFYUI_ENV_URL = process.env.DEV_SERVER_COMFYUI_URL
|
const DEV_SERVER_COMFYUI_ENV_URL = process.env.DEV_SERVER_COMFYUI_URL
|
||||||
const IS_CLOUD_URL = DEV_SERVER_COMFYUI_ENV_URL?.includes('.comfy.org')
|
const IS_CLOUD_URL = DEV_SERVER_COMFYUI_ENV_URL?.includes('.comfy.org')
|
||||||
|
|
||||||
const DISTRIBUTION = (process.env.DISTRIBUTION ||
|
const DISTRIBUTION: 'desktop' | 'localhost' | 'cloud' =
|
||||||
(IS_CLOUD_URL ? 'cloud' : 'localhost')) as 'desktop' | 'localhost' | 'cloud'
|
process.env.DISTRIBUTION === 'desktop' ||
|
||||||
|
process.env.DISTRIBUTION === 'localhost' ||
|
||||||
|
process.env.DISTRIBUTION === 'cloud'
|
||||||
|
? process.env.DISTRIBUTION
|
||||||
|
: IS_CLOUD_URL
|
||||||
|
? 'cloud'
|
||||||
|
: 'localhost'
|
||||||
|
|
||||||
// Disable Vue DevTools for production cloud distribution
|
// Disable Vue DevTools for production cloud distribution
|
||||||
const DISABLE_VUE_PLUGINS =
|
const DISABLE_VUE_PLUGINS =
|
||||||
@@ -43,39 +49,9 @@ const DEV_SEVER_FALLBACK_URL =
|
|||||||
const DEV_SERVER_COMFYUI_URL =
|
const DEV_SERVER_COMFYUI_URL =
|
||||||
DEV_SERVER_COMFYUI_ENV_URL || DEV_SEVER_FALLBACK_URL
|
DEV_SERVER_COMFYUI_ENV_URL || DEV_SEVER_FALLBACK_URL
|
||||||
|
|
||||||
// Optional: Add API key to .env as STAGING_API_KEY if needed for cloud authentication
|
// Cloud proxy configuration
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cloud endpoint configuration overrides
|
|
||||||
const cloudSecureConfig =
|
|
||||||
DISTRIBUTION === 'cloud'
|
|
||||||
? {
|
|
||||||
secure: false
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
|
|
||||||
const cloudProxyConfig =
|
const cloudProxyConfig =
|
||||||
DISTRIBUTION === 'cloud'
|
DISTRIBUTION === 'cloud' ? { secure: false, changeOrigin: true } : {}
|
||||||
? {
|
|
||||||
...cloudSecureConfig,
|
|
||||||
changeOrigin: true
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
|
|
||||||
const cloudProxyConfigWithAuth =
|
|
||||||
DISTRIBUTION === 'cloud'
|
|
||||||
? {
|
|
||||||
...cloudProxyConfig,
|
|
||||||
configure: addAuthHeaders
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
|
|
||||||
const BUILD_FLAGS = {
|
const BUILD_FLAGS = {
|
||||||
REQUIRE_SUBSCRIPTION: process.env.REQUIRE_SUBSCRIPTION === 'true'
|
REQUIRE_SUBSCRIPTION: process.env.REQUIRE_SUBSCRIPTION === 'true'
|
||||||
@@ -105,12 +81,12 @@ export default defineConfig({
|
|||||||
proxy: {
|
proxy: {
|
||||||
'/internal': {
|
'/internal': {
|
||||||
target: DEV_SERVER_COMFYUI_URL,
|
target: DEV_SERVER_COMFYUI_URL,
|
||||||
...cloudProxyConfigWithAuth
|
...cloudProxyConfig
|
||||||
},
|
},
|
||||||
|
|
||||||
'/api': {
|
'/api': {
|
||||||
target: DEV_SERVER_COMFYUI_URL,
|
target: DEV_SERVER_COMFYUI_URL,
|
||||||
...cloudProxyConfigWithAuth,
|
...cloudProxyConfig,
|
||||||
bypass: (req, res, _options) => {
|
bypass: (req, res, _options) => {
|
||||||
// Return empty array for extensions API as these modules
|
// Return empty array for extensions API as these modules
|
||||||
// are not on vite's dev server.
|
// are not on vite's dev server.
|
||||||
@@ -133,26 +109,24 @@ export default defineConfig({
|
|||||||
'/ws': {
|
'/ws': {
|
||||||
target: DEV_SERVER_COMFYUI_URL,
|
target: DEV_SERVER_COMFYUI_URL,
|
||||||
ws: true,
|
ws: true,
|
||||||
...cloudProxyConfigWithAuth
|
...cloudProxyConfig
|
||||||
},
|
},
|
||||||
|
|
||||||
'/workflow_templates': {
|
'/workflow_templates': {
|
||||||
target: DEV_SERVER_COMFYUI_URL,
|
target: DEV_SERVER_COMFYUI_URL,
|
||||||
...cloudProxyConfigWithAuth
|
...cloudProxyConfig
|
||||||
},
|
},
|
||||||
|
|
||||||
// Proxy extension assets (images/videos) under /extensions to the ComfyUI backend
|
|
||||||
'/extensions': {
|
'/extensions': {
|
||||||
target: DEV_SERVER_COMFYUI_URL,
|
target: DEV_SERVER_COMFYUI_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
...cloudSecureConfig
|
...cloudProxyConfig
|
||||||
},
|
},
|
||||||
|
|
||||||
// Proxy docs markdown from backend
|
|
||||||
'/docs': {
|
'/docs': {
|
||||||
target: DEV_SERVER_COMFYUI_URL,
|
target: DEV_SERVER_COMFYUI_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
...cloudSecureConfig
|
...cloudProxyConfig
|
||||||
},
|
},
|
||||||
|
|
||||||
...(!DISABLE_TEMPLATES_PROXY
|
...(!DISABLE_TEMPLATES_PROXY
|
||||||
|
|||||||
Reference in New Issue
Block a user