Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

Coding On Stard93e5aa44414
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(