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
This commit is contained in:
gorkem-bwl
2026-03-04 15:29:44 -05:00
parent 189293b04d
commit 888b399a4f
+16 -2
View File
@@ -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({