Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { Router, Request, Response, NextFunction } from "express";
import { config } from "./config/config";
import path from "node:path";

const isProduction = config.server.nodeEnv === "production";
const basePath = isProduction ? path.join(__dirname, "./routes/*.ts") : path.join(__dirname, "./routes/*.js");

const options: swaggerJsdoc.Options = {
definition: {
openapi: "3.0.0",
Expand All @@ -19,13 +22,9 @@ const options: swaggerJsdoc.Options = {
},
servers: [
{
url: `http://localhost:${config.server.port}`,
description: "Local development server",
},
{
url: "https://api.yourproduction.com",
description: "Production server",
},
url: "/api/v1",
description: "API v1",
}
],
components: {
securitySchemes: {
Expand All @@ -49,8 +48,7 @@ const options: swaggerJsdoc.Options = {
},
// Path to the API routes files where JSDoc comments are
apis: [
path.join(__dirname, "./routes/*.ts"),
path.join(__dirname, "./routes/*.js"),
basePath,
],
};

Expand Down
Loading