mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-07-17 09:18:26 +00:00
refactor: use axios interceptor instead of watcher for runtime base URL
Reading the base URL at axios.create() time captures whatever remoteConfig holds at module-load — which on OSS is the empty default, because static imports are hoisted above main.ts's top-level 'await refreshRemoteConfig()'. A subsequent 'watch' never fires because the value is already correct by the time the watcher is established. A request-time interceptor reads the current URL on every call, which is both simpler and actually correct.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import type { AxiosError, AxiosResponse } from 'axios'
|
||||
import axios from 'axios'
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { getComfyApiBaseUrl } from '@/config/comfyApi'
|
||||
import type { components, operations } from '@/types/comfyRegistryTypes'
|
||||
import { isAbortError } from '@/utils/typeGuardUtil'
|
||||
|
||||
const registryApiClient = axios.create({
|
||||
baseURL: getComfyApiBaseUrl(),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -17,6 +16,14 @@ const registryApiClient = axios.create({
|
||||
}
|
||||
})
|
||||
|
||||
// Resolve the base URL per request so server-provided overrides applied
|
||||
// after this module is first imported (e.g. via remoteConfig) take effect
|
||||
// on the next call, without temporal coupling to module-load order.
|
||||
registryApiClient.interceptors.request.use((config) => {
|
||||
config.baseURL = getComfyApiBaseUrl()
|
||||
return config
|
||||
})
|
||||
|
||||
/**
|
||||
* Service for interacting with the Comfy Registry API
|
||||
*/
|
||||
@@ -24,13 +31,6 @@ export const useComfyRegistryService = () => {
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
watch(
|
||||
() => getComfyApiBaseUrl(),
|
||||
(url) => {
|
||||
registryApiClient.defaults.baseURL = url
|
||||
}
|
||||
)
|
||||
|
||||
const handleApiError = (
|
||||
err: unknown,
|
||||
context: string,
|
||||
|
||||
Reference in New Issue
Block a user