refactor(system): changes to keep everything more tidy and less drilling

This commit is contained in:
2025-12-22 08:54:18 -06:00
parent a7be989b4f
commit 33ffdb2264
9 changed files with 826 additions and 63 deletions

View File

@@ -1,10 +1,11 @@
import express from "express";
import { setupRoutes } from "@/src/routes/routeHandler.route.js";
import { setupRoutes } from "./src/routeHandler.route.js";
const port = Number(process.env.PORT);
export const baseUrl = "";
const startApp = async () => {
const app = express();
const baseUrl = "";
setupRoutes(baseUrl, app);
app.listen(port, () => {

View File

@@ -8,7 +8,9 @@ import type { Express } from "express";
import { apiReference } from "@scalar/express-api-reference";
// const port = 3000;
import type { OpenAPIV3_1 } from "openapi-types";
import { healthSpec } from "./specs/health.spec.js";
// all the specs
import { statusSpec } from "../scaler/stats.spec.js";
export const openApiBase: OpenAPIV3_1.Document = {
openapi: "3.1.0",
@@ -54,7 +56,7 @@ export const setupApiDocsRoutes = (baseUrl: string, app: Express) => {
const fullSpec = {
...openApiBase,
paths: {
...healthSpec,
...statusSpec,
// Add more specs here as you build features
},

View File

@@ -0,0 +1,11 @@
import type { Express } from "express";
// import the routes and route setups
import { setupApiDocsRoutes } from "./configs/scaler.config.js";
import stats from "./routes/stats.route.js";
export const setupRoutes = (baseUrl: string, app: Express) => {
//setup all the routes
setupApiDocsRoutes(baseUrl, app);
app.use(`${baseUrl}/api/stats`, stats);
};

View File

@@ -1,13 +0,0 @@
import type { Express, Response } from "express";
import { setupApiDocsRoutes } from "../scaler/config.js";
export const setupRoutes = (baseUrl: string, app: Express) => {
//setup all the routes
setupApiDocsRoutes(baseUrl, app);
app.get(`${baseUrl}/`, (_, res: Response) => {
res.status(200).json({
success: true,
message: "This is just an example of this working",
});
});
};

View File

@@ -0,0 +1,16 @@
import { Router } from "express";
const router = Router();
router.get("/", async (_, res) => {
const used = process.memoryUsage();
res.status(200).json({
status: "ok",
uptime: process.uptime(),
memoryUsage: `Heap: ${(used.heapUsed / 1024 / 1024).toFixed(2)} MB / RSS: ${(
used.rss / 1024 / 1024
).toFixed(2)} MB`,
});
});
export default router;

View File

@@ -1,37 +0,0 @@
import type { OpenAPIV3_1 } from "openapi-types";
export const healthSpec: OpenAPIV3_1.PathsObject = {
"/": {
get: {
summary: "Health check",
description: "Check if the API is running",
//tags: ["Health"],
responses: {
"200": {
description: "API is healthy",
content: {
"application/json": {
schema: {
type: "object",
properties: {
success: {
type: "boolean",
example: true,
},
message: {
type: "string",
example: "LST v3 is running",
},
timestamp: {
type: "string",
format: "date-time",
},
},
},
},
},
},
},
},
},
};

View File

@@ -0,0 +1,39 @@
import type { OpenAPIV3_1 } from "openapi-types";
export const statusSpec: OpenAPIV3_1.PathsObject = {
"/api/stats": {
get: {
summary: "Server Status",
description: "Checks the status of the server.",
tags: ["System"],
responses: {
"200": {
description: "Stats from the server",
content: {
"application/json": {
schema: {
type: "object",
properties: {
status: {
type: "string",
format: "ok",
example: "ok",
},
uptime: {
type: "number",
format: "3454.34",
example: 3454.34,
},
memoryUsage: {
type: "string",
format: "Heap: 11.62 MB / RSS: 86.31 MB",
},
},
},
},
},
},
},
},
},
};

760
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,7 @@
"@commitlint/cli": "^18.4.0",
"@commitlint/config-conventional": "^18.4.0",
"@types/express": "^5.0.6",
"@types/mssql": "^9.1.8",
"@types/node": "^24.10.1",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.8",
@@ -49,6 +50,7 @@
"axios": "^1.13.2",
"better-auth": "^1.4.6",
"express": "^5.2.1",
"mssql": "^12.2.0",
"npm-check-updates": "^19.1.2"
},
"config": {