scaler added and confirmed builds work

This commit is contained in:
2025-12-13 12:07:34 -06:00
parent c3b2acd033
commit 3bcc6f89b3
7 changed files with 161 additions and 51 deletions

View File

@@ -0,0 +1,13 @@
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

@@ -1,34 +0,0 @@
import { apiReference } from "@scalar/express-api-reference";
import type { Express, Response } from "express";
import { openApiSpec } from "../scaler/config.js";
export const setupRoutes = (app: Express) => {
/**
* @openapi
* /:
* get:
* summary: Health check
* responses:
* 200:
* description: Success
*/
app.get("/", (_, res: Response) => {
res.status(200).json({
success: true,
message: "This is just an example of this working",
});
});
app.get("/api/docs.json", (_, res) => {
res.json(openApiSpec);
});
app.use(
"/api/dos",
apiReference({
// Put your OpenAPI url here:
url: "/openapi.json",
theme: "purple",
}),
);
};

View File

@@ -1,12 +1,16 @@
//import path from "node:path";
//import { fileURLToPath } from "node:url";
import type { OpenAPIV3_1 } from "openapi-types";
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;
export const openApiSpec: OpenAPIV3_1.Document = {
import type { OpenAPIV3_1 } from "openapi-types";
import { healthSpec } from "./specs/health.spec.js";
export const openApiBase: OpenAPIV3_1.Document = {
openapi: "3.1.0",
info: {
title: "LST API",
@@ -27,12 +31,87 @@ export const openApiSpec: OpenAPIV3_1.Document = {
bearerFormat: "JWT",
},
},
schemas: {
Error: {
type: "object",
properties: {
error: { type: "string" },
message: { type: "string" },
},
},
},
},
paths: {},
tags: [
{ name: "Health", description: "Health check endpoints" },
{ name: "Printing", description: "Label printing operations" },
{ name: "Silo", description: "Silo management" },
{ name: "TMS", description: "TMS integration" },
// { 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: {
...healthSpec,
// 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"],
},
}),
);
};

View File

@@ -0,0 +1,37 @@
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",
},
},
},
},
},
},
},
},
},
};