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:
Hunter Senft-Grupp
2026-05-31 13:38:20 -04:00
parent 112b3526a9
commit 2ce68c8a58

View File

@@ -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,