mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-22 05:19:03 +00:00
fix: use local API base in cloud dev
Keep local cloud development on the Vite proxy path so user-scoped customer requests do not leak to staging.
This commit is contained in:
1
global.d.ts
vendored
1
global.d.ts
vendored
@@ -5,6 +5,7 @@ declare const __SENTRY_DSN__: string
|
||||
declare const __ALGOLIA_APP_ID__: string
|
||||
declare const __ALGOLIA_API_KEY__: string
|
||||
declare const __USE_PROD_CONFIG__: boolean
|
||||
declare const __DEV_SERVER_COMFYUI_URL__: string
|
||||
|
||||
interface ImpactQueueFunction {
|
||||
(...args: unknown[]): void
|
||||
|
||||
@@ -11,6 +11,7 @@ declare global {
|
||||
const __ALGOLIA_APP_ID__: string
|
||||
const __ALGOLIA_API_KEY__: string
|
||||
const __USE_PROD_CONFIG__: boolean
|
||||
const __DEV_SERVER_COMFYUI_URL__: string
|
||||
const __DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud'
|
||||
const __IS_NIGHTLY__: boolean
|
||||
}
|
||||
@@ -22,6 +23,7 @@ type GlobalWithDefines = typeof globalThis & {
|
||||
__ALGOLIA_APP_ID__: string
|
||||
__ALGOLIA_API_KEY__: string
|
||||
__USE_PROD_CONFIG__: boolean
|
||||
__DEV_SERVER_COMFYUI_URL__: string
|
||||
__DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud'
|
||||
__IS_NIGHTLY__: boolean
|
||||
window?: Record<string, unknown>
|
||||
@@ -37,6 +39,7 @@ globalWithDefines.__SENTRY_DSN__ = ''
|
||||
globalWithDefines.__ALGOLIA_APP_ID__ = ''
|
||||
globalWithDefines.__ALGOLIA_API_KEY__ = ''
|
||||
globalWithDefines.__USE_PROD_CONFIG__ = false
|
||||
globalWithDefines.__DEV_SERVER_COMFYUI_URL__ = ''
|
||||
globalWithDefines.__DISTRIBUTION__ = 'localhost'
|
||||
globalWithDefines.__IS_NIGHTLY__ = false
|
||||
|
||||
|
||||
26
src/config/comfyApi.test.ts
Normal file
26
src/config/comfyApi.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { getComfyApiBaseUrlForEnvironment } from '@/config/comfyApi'
|
||||
|
||||
describe('comfy api config', () => {
|
||||
it('uses same-origin API calls for cloud local development', () => {
|
||||
expect(
|
||||
getComfyApiBaseUrlForEnvironment({
|
||||
isCloudDistribution: true,
|
||||
isDev: true,
|
||||
devServerComfyUIUrl: 'http://127.0.0.1:8188',
|
||||
useProdConfig: false
|
||||
})
|
||||
).toBe('')
|
||||
})
|
||||
|
||||
it('keeps staging API for non-local staging builds', () => {
|
||||
expect(
|
||||
getComfyApiBaseUrlForEnvironment({
|
||||
isCloudDistribution: true,
|
||||
isDev: false,
|
||||
useProdConfig: false
|
||||
})
|
||||
).toBe('https://stagingapi.comfy.org')
|
||||
})
|
||||
})
|
||||
@@ -10,34 +10,68 @@ const STAGING_API_BASE_URL = 'https://stagingapi.comfy.org'
|
||||
const PROD_PLATFORM_BASE_URL = 'https://platform.comfy.org'
|
||||
const STAGING_PLATFORM_BASE_URL = 'https://stagingplatform.comfy.org'
|
||||
|
||||
const BUILD_TIME_API_BASE_URL = __USE_PROD_CONFIG__
|
||||
? PROD_API_BASE_URL
|
||||
: STAGING_API_BASE_URL
|
||||
type ComfyApiEnvironment = {
|
||||
isCloudDistribution: boolean
|
||||
isDev: boolean
|
||||
devServerComfyUIUrl?: string
|
||||
useProdConfig: boolean
|
||||
}
|
||||
|
||||
const BUILD_TIME_PLATFORM_BASE_URL = __USE_PROD_CONFIG__
|
||||
? PROD_PLATFORM_BASE_URL
|
||||
: STAGING_PLATFORM_BASE_URL
|
||||
const localOriginPattern =
|
||||
/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(?::\d+)?(?:\/|$)/
|
||||
|
||||
export function getComfyApiBaseUrl(): string {
|
||||
if (!isCloud) {
|
||||
return BUILD_TIME_API_BASE_URL
|
||||
function buildTimeApiBaseUrl(useProdConfig: boolean): string {
|
||||
return useProdConfig ? PROD_API_BASE_URL : STAGING_API_BASE_URL
|
||||
}
|
||||
|
||||
function buildTimePlatformBaseUrl(useProdConfig: boolean): string {
|
||||
return useProdConfig ? PROD_PLATFORM_BASE_URL : STAGING_PLATFORM_BASE_URL
|
||||
}
|
||||
|
||||
function isLocalDevServer(url?: string): boolean {
|
||||
return url ? localOriginPattern.test(url) : false
|
||||
}
|
||||
|
||||
export function getComfyApiBaseUrlForEnvironment({
|
||||
isCloudDistribution,
|
||||
isDev,
|
||||
devServerComfyUIUrl,
|
||||
useProdConfig
|
||||
}: ComfyApiEnvironment): string {
|
||||
const buildTimeApiBaseUrlValue = buildTimeApiBaseUrl(useProdConfig)
|
||||
if (!isCloudDistribution) {
|
||||
return buildTimeApiBaseUrlValue
|
||||
}
|
||||
if (isDev && isLocalDevServer(devServerComfyUIUrl)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return configValueOrDefault(
|
||||
remoteConfig.value,
|
||||
'comfy_api_base_url',
|
||||
BUILD_TIME_API_BASE_URL
|
||||
buildTimeApiBaseUrlValue
|
||||
)
|
||||
}
|
||||
|
||||
export function getComfyApiBaseUrl(): string {
|
||||
return getComfyApiBaseUrlForEnvironment({
|
||||
isCloudDistribution: isCloud,
|
||||
isDev: import.meta.env.DEV,
|
||||
devServerComfyUIUrl: __DEV_SERVER_COMFYUI_URL__,
|
||||
useProdConfig: __USE_PROD_CONFIG__
|
||||
})
|
||||
}
|
||||
|
||||
export function getComfyPlatformBaseUrl(): string {
|
||||
const buildTimePlatformBaseUrlValue =
|
||||
buildTimePlatformBaseUrl(__USE_PROD_CONFIG__)
|
||||
if (!isCloud) {
|
||||
return BUILD_TIME_PLATFORM_BASE_URL
|
||||
return buildTimePlatformBaseUrlValue
|
||||
}
|
||||
|
||||
return configValueOrDefault(
|
||||
remoteConfig.value,
|
||||
'comfy_platform_base_url',
|
||||
BUILD_TIME_PLATFORM_BASE_URL
|
||||
buildTimePlatformBaseUrlValue
|
||||
)
|
||||
}
|
||||
|
||||
@@ -219,6 +219,11 @@ export default defineConfig({
|
||||
...cloudProxyConfig
|
||||
},
|
||||
|
||||
'/customers': {
|
||||
target: DEV_SERVER_COMFYUI_URL,
|
||||
...cloudProxyConfig
|
||||
},
|
||||
|
||||
'/ws': {
|
||||
target: DEV_SERVER_COMFYUI_URL,
|
||||
ws: true,
|
||||
@@ -630,6 +635,7 @@ export default defineConfig({
|
||||
__ALGOLIA_APP_ID__: JSON.stringify(process.env.ALGOLIA_APP_ID || ''),
|
||||
__ALGOLIA_API_KEY__: JSON.stringify(process.env.ALGOLIA_API_KEY || ''),
|
||||
__USE_PROD_CONFIG__: process.env.USE_PROD_CONFIG === 'true',
|
||||
__DEV_SERVER_COMFYUI_URL__: JSON.stringify(DEV_SERVER_COMFYUI_URL),
|
||||
__DISTRIBUTION__: JSON.stringify(DISTRIBUTION),
|
||||
__IS_NIGHTLY__: JSON.stringify(IS_NIGHTLY)
|
||||
},
|
||||
|
||||
@@ -46,6 +46,7 @@ globalThis.__SENTRY_DSN__ = ''
|
||||
globalThis.__ALGOLIA_APP_ID__ = ''
|
||||
globalThis.__ALGOLIA_API_KEY__ = ''
|
||||
globalThis.__USE_PROD_CONFIG__ = false
|
||||
globalThis.__DEV_SERVER_COMFYUI_URL__ = ''
|
||||
globalThis.__DISTRIBUTION__ = 'localhost'
|
||||
globalThis.__IS_NIGHTLY__ = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user