From 888b399a4f8c659093c6db466449f89b5bf5a82e Mon Sep 17 00:00:00 2001 From: gorkem-bwl Date: Wed, 4 Mar 2026 15:29:44 -0500 Subject: [PATCH] fix: dynamically set Swagger UI server URL from request ## Changes - Swagger UI now prepends the current server URL (protocol + host) to the servers list, so it works correctly in remote/Docker environments instead of always pointing to localhost. ## Closes Fixes #3339 --- server/src/app.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/server/src/app.ts b/server/src/app.ts index fea81ba07..f7cff5418 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -74,8 +74,22 @@ export const createApp = ({ }, }) ); - // Swagger UI - app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(openApiSpec)); + // Swagger UI — dynamically set server URL from request + app.use("/api-docs", swaggerUi.serve, (req, res, next) => { + const protocol = req.protocol; + const host = req.get("host"); + const dynamicSpec = { + ...openApiSpec, + servers: [ + { + url: `${protocol}://${host}/api/v1`, + description: "Current Server", + }, + ...openApiSpec.servers, + ], + }; + swaggerUi.setup(dynamicSpec)(req, res, next); + }); app.use("/api/v1/health", (req, res) => { res.json({