From 066ca9e552f5f455bb9456994361c6ac9e08297c Mon Sep 17 00:00:00 2001 From: Fred Date: Thu, 14 Mar 2024 03:03:46 +0800 Subject: [PATCH] fix: auto migrate proxy config --- app/store/sync.ts | 11 ++++++++++- app/utils/cors.ts | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/store/sync.ts b/app/store/sync.ts index 5ff1cc6e56c..674ff674420 100644 --- a/app/store/sync.ts +++ b/app/store/sync.ts @@ -118,7 +118,7 @@ export const useSyncStore = createPersistStore( }), { name: StoreKey.Sync, - version: 1.1, + version: 1.2, migrate(persistedState, version) { const newState = persistedState as typeof DEFAULT_SYNC_STATE; @@ -127,6 +127,15 @@ export const useSyncStore = createPersistStore( newState.upstash.username = STORAGE_KEY; } + if (version < 1.2) { + if ( + (persistedState as typeof DEFAULT_SYNC_STATE).proxyUrl === + "/api/cors/" + ) { + newState.proxyUrl = ""; + } + } + return newState as any; }, }, diff --git a/app/utils/cors.ts b/app/utils/cors.ts index 93956a7b5c7..fa348f9bf5d 100644 --- a/app/utils/cors.ts +++ b/app/utils/cors.ts @@ -4,6 +4,9 @@ import { ApiPath, DEFAULT_API_HOST } from "../constant"; export function corsPath(path: string) { const baseUrl = getClientConfig()?.isApp ? `${DEFAULT_API_HOST}` : ""; + if (baseUrl === "" && path === "") { + return ""; + } if (!path.startsWith("/")) { path = "/" + path; }