fix(web): append /api/v1 when SSR reads MARKETPLACE_API_URL (#41824)

Co-authored-by: fatelei <fatelei@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: zxhlyh <jasonapring2015@outlook.com>
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: 姜涵煦 <hanxujiang@jianghanxudeMacBook-Pro-2.local>
Co-authored-by: L1nSn0w <l1nsn0w@qq.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
This commit is contained in:
Coding On Star 2026-09-04 10:38:53 +00:00 committed by GitHub
parent e6c9846726
commit d93e5aa444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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