From d93e5aa4441499dc634c226fd3d98e05f9f792ef Mon Sep 17 00:00:00 2001 From: Coding On Star <447357187@qq.com> Date: Fri, 4 Sep 2026 10:38:53 +0000 Subject: [PATCH] fix(web): append /api/v1 when SSR reads MARKETPLACE_API_URL (#41824) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: fatelei Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: zxhlyh Co-authored-by: CodingOnStar Co-authored-by: Cursor Co-authored-by: 姜涵煦 Co-authored-by: L1nSn0w Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> --- web/config/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/config/index.ts b/web/config/index.ts index 018373396f6..a755e101a31 100644 --- a/web/config/index.ts +++ b/web/config/index.ts @@ -14,14 +14,20 @@ const getStringConfig = (envVar: string | undefined, defaultValue: string) => { const isLocalMarketplaceApiUrl = (url: string | undefined) => /^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::|\/)/i.test(url ?? '') -// NEXT_PUBLIC_* is inlined at build. The standalone marketplace image sets -// MARKETPLACE_API_URL at runtime instead, so SSR must read that here or it -// falls through to localhost:5002 and creator pages throw. +// Docker entrypoint sets NEXT_PUBLIC_MARKETPLACE_API_PREFIX=${MARKETPLACE_API_URL}/api/v1. +// MARKETPLACE_API_URL itself is the site origin (no /api/v1). Standalone marketplace +// images may set MARKETPLACE_API_URL at runtime for SSR; normalize the same way +// entrypoint does so console SSR does not call the HTML origin and fail Templates. +const marketplaceApiPrefixFromUrl = (url: string) => { + const trimmed = url.replace(/\/$/, '') + return trimmed.endsWith('/api/v1') ? trimmed : `${trimmed}/api/v1` +} + const runtimeMarketplaceApiUrl = typeof globalThis.window === 'undefined' && process.env.MARKETPLACE_API_URL && !isLocalMarketplaceApiUrl(process.env.MARKETPLACE_API_URL) - ? process.env.MARKETPLACE_API_URL + ? marketplaceApiPrefixFromUrl(process.env.MARKETPLACE_API_URL) : undefined export const API_PREFIX = getStringConfig(