Files
lst_v3/backend/src/configs/scaler.config.ts

125 lines
2.8 KiB
TypeScript

//import path from "node:path";
//import { fileURLToPath } from "node:url";
import type { Express } from "express";
//const __filename = fileURLToPath(import.meta.url);
// const __dirname = path.dirname(__filename);
import { apiReference } from "@scalar/express-api-reference";
// const port = 3000;
import type { OpenAPIV3_1 } from "openapi-types";
import { prodRestartSpec } from "../scaler/prodSqlRestart.spec.js";
import { prodStartSpec } from "../scaler/prodSqlStart.spec.js";
import { prodStopSpec } from "../scaler/prodSqlStop.spec.js";
// all the specs
import { statusSpec } from "../scaler/stats.spec.js";
export const openApiBase: OpenAPIV3_1.Document = {
openapi: "3.1.0",
info: {
title: "LST API",
version: "3.0.0",
description: "Label System Tracking API",
},
servers: [
{
url: `http://localhost:3000${process.env.NODE_ENV?.trim() !== "production" ? "/lst" : "/"}`,
description: "Development server",
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
// schemas: {
// Error: {
// type: "object",
// properties: {
// error: { type: "string" },
// message: { type: "string" },
// },
// },
// },
},
tags: [
// { name: "Health", description: "Health check endpoints" },
// { name: "Printing", description: "Label printing operations" },
// { name: "Silo", description: "Silo management" },
// { name: "TMS", description: "TMS integration" },
],
paths: {}, // Will be populated
};
export const setupApiDocsRoutes = (baseUrl: string, app: Express) => {
const fullSpec = {
...openApiBase,
paths: {
...statusSpec,
...prodStartSpec,
...prodStopSpec,
...prodRestartSpec,
// Add more specs here as you build features
},
};
app.get(`${baseUrl}/api/docs.json`, (_, res) => {
res.json(fullSpec);
});
app.use(
`${baseUrl}/api/docs`,
apiReference({
url: `${baseUrl}/api/docs.json`,
theme: "purple",
darkMode: true,
authentication: {
securitySchemes: {
httpBasic: {
username: "username",
password: "password",
},
},
},
defaultHttpClient: {
targetKey: "node",
clientKey: "axios",
},
documentDownloadType: "json",
hideClientButton: true,
hiddenClients: {
// C
c: ["libcurl"],
// Clojure
clojure: ["clj_http"],
// C#
csharp: ["httpclient", "restsharp"],
// Dart
dart: ["http"],
// F#
fsharp: ["httpclient"],
// Java
java: ["asynchttp", "nethttp", "okhttp", "unirest"],
// Objective-C
objc: ["nsurlsession"],
// OCaml
ocaml: ["cohttp"],
// PHP
php: ["curl", "guzzle"],
// R
r: ["httr"],
// Ruby
ruby: ["native"],
// Rust
rust: ["reqwest"],
// Swift
swift: ["nsurlsession"],
},
}),
);
};