Skip to content

Commit c71ec35

Browse files
authored
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)
1 parent 7b213f1 commit c71ec35

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

vite.config.mts

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ const GENERATE_SOURCEMAP = process.env.GENERATE_SOURCEMAP !== 'false'
2727
const DEV_SERVER_COMFYUI_ENV_URL = process.env.DEV_SERVER_COMFYUI_URL
2828
const IS_CLOUD_URL = DEV_SERVER_COMFYUI_ENV_URL?.includes('.comfy.org')
2929

30-
const DISTRIBUTION = (process.env.DISTRIBUTION ||
31-
(IS_CLOUD_URL ? 'cloud' : 'localhost')) as 'desktop' | 'localhost' | 'cloud'
30+
const DISTRIBUTION: 'desktop' | 'localhost' | 'cloud' =
31+
process.env.DISTRIBUTION === 'desktop' ||
32+
process.env.DISTRIBUTION === 'localhost' ||
33+
process.env.DISTRIBUTION === 'cloud'
34+
? process.env.DISTRIBUTION
35+
: IS_CLOUD_URL
36+
? 'cloud'
37+
: 'localhost'
3238

3339
// Disable Vue DevTools for production cloud distribution
3440
const DISABLE_VUE_PLUGINS =
@@ -43,39 +49,9 @@ const DEV_SEVER_FALLBACK_URL =
4349
const DEV_SERVER_COMFYUI_URL =
4450
DEV_SERVER_COMFYUI_ENV_URL || DEV_SEVER_FALLBACK_URL
4551

46-
// Optional: Add API key to .env as STAGING_API_KEY if needed for cloud authentication
47-
const addAuthHeaders = (proxy: any) => {
48-
proxy.on('proxyReq', (proxyReq: any, _req: any, _res: any) => {
49-
const apiKey = process.env.STAGING_API_KEY
50-
if (apiKey) {
51-
proxyReq.setHeader('X-API-KEY', apiKey)
52-
}
53-
})
54-
}
55-
56-
// Cloud endpoint configuration overrides
57-
const cloudSecureConfig =
58-
DISTRIBUTION === 'cloud'
59-
? {
60-
secure: false
61-
}
62-
: {}
63-
52+
// Cloud proxy configuration
6453
const cloudProxyConfig =
65-
DISTRIBUTION === 'cloud'
66-
? {
67-
...cloudSecureConfig,
68-
changeOrigin: true
69-
}
70-
: {}
71-
72-
const cloudProxyConfigWithAuth =
73-
DISTRIBUTION === 'cloud'
74-
? {
75-
...cloudProxyConfig,
76-
configure: addAuthHeaders
77-
}
78-
: {}
54+
DISTRIBUTION === 'cloud' ? { secure: false, changeOrigin: true } : {}
7955

8056
const BUILD_FLAGS = {
8157
REQUIRE_SUBSCRIPTION: process.env.REQUIRE_SUBSCRIPTION === 'true'
@@ -105,12 +81,12 @@ export default defineConfig({
10581
proxy: {
10682
'/internal': {
10783
target: DEV_SERVER_COMFYUI_URL,
108-
...cloudProxyConfigWithAuth
84+
...cloudProxyConfig
10985
},
11086

11187
'/api': {
11288
target: DEV_SERVER_COMFYUI_URL,
113-
...cloudProxyConfigWithAuth,
89+
...cloudProxyConfig,
11490
bypass: (req, res, _options) => {
11591
// Return empty array for extensions API as these modules
11692
// are not on vite's dev server.
@@ -133,26 +109,24 @@ export default defineConfig({
133109
'/ws': {
134110
target: DEV_SERVER_COMFYUI_URL,
135111
ws: true,
136-
...cloudProxyConfigWithAuth
112+
...cloudProxyConfig
137113
},
138114

139115
'/workflow_templates': {
140116
target: DEV_SERVER_COMFYUI_URL,
141-
...cloudProxyConfigWithAuth
117+
...cloudProxyConfig
142118
},
143119

144-
// Proxy extension assets (images/videos) under /extensions to the ComfyUI backend
145120
'/extensions': {
146121
target: DEV_SERVER_COMFYUI_URL,
147122
changeOrigin: true,
148-
...cloudSecureConfig
123+
...cloudProxyConfig
149124
},
150125

151-
// Proxy docs markdown from backend
152126
'/docs': {
153127
target: DEV_SERVER_COMFYUI_URL,
154128
changeOrigin: true,
155-
...cloudSecureConfig
129+
...cloudProxyConfig
156130
},
157131

158132
...(!DISABLE_TEMPLATES_PROXY

0 commit comments

Comments
 (0)