From 9d9ca63d7c9ab3e3ea168cf2add9c7baf2b9ed15 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sat, 1 Nov 2025 00:05:56 -0500 Subject: [PATCH] feat(added in swagger): added the base for swagger to implement fully later --- app/main.ts | 16 ++++++++++++++-- app/src/pkg/apiDocs/swaggerOptions.ts | 11 +++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 app/src/pkg/apiDocs/swaggerOptions.ts diff --git a/app/main.ts b/app/main.ts index 93e7129..41f45b5 100644 --- a/app/main.ts +++ b/app/main.ts @@ -8,6 +8,8 @@ import { createProxyMiddleware, fixRequestBody } from "http-proxy-middleware"; import morgan from "morgan"; import os from "os"; import { dirname, join } from "path"; +import swaggerJsdoc from "swagger-jsdoc"; +import swaggerUi from "swagger-ui-express"; import { fileURLToPath } from "url"; import { userMigrate } from "./src/internal/auth/controller/userMigrate.js"; import { schedulerManager } from "./src/internal/logistics/controller/schedulerManager.js"; @@ -15,6 +17,8 @@ import { printers } from "./src/internal/ocp/printers/printers.js"; import { setupRoutes } from "./src/internal/routerHandler/routeHandler.js"; import { baseModules } from "./src/internal/system/controller/modules/baseModules.js"; import { baseSettings } from "./src/internal/system/controller/settings/baseSettings.js"; +import { addListeners } from "./src/internal/system/utlis/addListeners.js"; +import { swaggerOptions } from "./src/pkg/apiDocs/swaggerOptions.js"; import { auth } from "./src/pkg/auth/auth.js"; import { db } from "./src/pkg/db/db.js"; import { settings } from "./src/pkg/db/schema/settings.js"; @@ -30,7 +34,7 @@ import { setupIoServer } from "./src/ws/server.js"; const main = async () => { const env = validateEnv(process.env); - const PORT = Number(env.VITE_PORT) || 4200; + const PORT = Number(process.env.VITE_PORT) || 4200; //create the logger const log = createLogger({ module: "system", subModule: "main start" }); @@ -159,7 +163,14 @@ const main = async () => { }), ); - // docs and api stuff + // docs and routes + const openapiSpec: any = swaggerJsdoc(swaggerOptions); + app.use( + basePath + "/api/docs", + swaggerUi.serve, + swaggerUi.setup(openapiSpec), + ); + app.use(basePath + "/d", express.static(join(__dirname, "../lstDocs/build"))); app.use( basePath + "/app", @@ -192,6 +203,7 @@ const main = async () => { // start up the v1listener v1Listener(); + addListeners(); userMigrate(); }, 5 * 1000); diff --git a/app/src/pkg/apiDocs/swaggerOptions.ts b/app/src/pkg/apiDocs/swaggerOptions.ts new file mode 100644 index 0000000..c205c37 --- /dev/null +++ b/app/src/pkg/apiDocs/swaggerOptions.ts @@ -0,0 +1,11 @@ +export const swaggerOptions = { + definition: { + openapi: "3.0.0", + info: { + title: "Logistics Support Tool", + version: "1.0.0", + }, + }, + // globs where swagger-jsdoc should look for annotations: + apis: ["../../src/**/*.ts"], +};