recator placement of code
This commit is contained in:
19
backend/configs/prodSql.config.ts
Normal file
19
backend/configs/prodSql.config.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type sql from "mssql";
|
||||
export const prodSqlConfig: sql.config = {
|
||||
server: `${process.env.PROD_SERVER}`,
|
||||
database: `AlplaPROD_${process.env.PROD_PLANT_TOKEN}_cus`,
|
||||
user: process.env.PROD_USER,
|
||||
password: process.env.PROD_PASSWORD,
|
||||
options: {
|
||||
encrypt: true,
|
||||
trustServerCertificate: true,
|
||||
},
|
||||
requestTimeout: 90000, // how long until we kill the query and fail it
|
||||
pool: {
|
||||
max: 20, // Maximum number of connections in the pool
|
||||
min: 0, // Minimum number of connections in the pool
|
||||
idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
|
||||
reapIntervalMillis: 1000, // how often to check for idle resources to destroy
|
||||
acquireTimeoutMillis: 100000, // How long until a complete timeout happens
|
||||
},
|
||||
};
|
||||
165
backend/configs/scaler.config.ts
Normal file
165
backend/configs/scaler.config.ts
Normal file
@@ -0,0 +1,165 @@
|
||||
//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 { datamartAddSpec } from "../scaler/datamartAdd.spec.js";
|
||||
import { datamartUpdateSpec } from "../scaler/datamartUpdate.spec.js";
|
||||
import { getDatamartSpec } from "../scaler/getDatamart.spec.js";
|
||||
import { prodLoginSpec } from "../scaler/login.spec.js";
|
||||
import { prodRestartSpec } from "../scaler/prodSqlRestart.spec.js";
|
||||
import { prodStartSpec } from "../scaler/prodSqlStart.spec.js";
|
||||
import { prodStopSpec } from "../scaler/prodSqlStop.spec.js";
|
||||
import { prodRegisterSpec } from "../scaler/register.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",
|
||||
},
|
||||
ApiKeyAuth: {
|
||||
type: "apiKey",
|
||||
description: "API key required for authentication",
|
||||
name: "api_key",
|
||||
in: "header",
|
||||
},
|
||||
basicAuth: {
|
||||
type: "http",
|
||||
scheme: "basic",
|
||||
description: "Basic authentication using username and password",
|
||||
},
|
||||
},
|
||||
// schemas: {
|
||||
// Error: {
|
||||
// type: "object",
|
||||
// properties: {
|
||||
// error: { type: "string" },
|
||||
// message: { type: "string" },
|
||||
// },
|
||||
// },
|
||||
// },.
|
||||
},
|
||||
|
||||
tags: [
|
||||
{
|
||||
name: "Auth",
|
||||
description:
|
||||
"Authentication section where you get and create users and api keys",
|
||||
},
|
||||
{
|
||||
name: "System",
|
||||
description: "All system endpoints that will be available to run",
|
||||
},
|
||||
{
|
||||
name: "Datamart",
|
||||
description:
|
||||
"All Special queries to run based on there names.\n Refer to the docs to see all possible queries that can be ran here, you can also run the getQueries to see available.",
|
||||
},
|
||||
// { name: "TMS", description: "TMS integration" },
|
||||
],
|
||||
paths: {}, // Will be populated
|
||||
};
|
||||
|
||||
export const setupApiDocsRoutes = (baseUrl: string, app: Express) => {
|
||||
const mergedDatamart = {
|
||||
"/api/datamart": {
|
||||
...(getDatamartSpec["/api/datamart"] ?? {}),
|
||||
...(datamartAddSpec["/api/datamart"] ?? {}),
|
||||
...(datamartUpdateSpec["/api/datamart"] ?? {}),
|
||||
},
|
||||
"/api/datamart/{name}": getDatamartSpec["/api/datamart/{name}"],
|
||||
};
|
||||
|
||||
const fullSpec = {
|
||||
...openApiBase,
|
||||
paths: {
|
||||
...statusSpec,
|
||||
...prodStartSpec,
|
||||
...prodStopSpec,
|
||||
...prodRestartSpec,
|
||||
...prodLoginSpec,
|
||||
...prodRegisterSpec,
|
||||
...mergedDatamart,
|
||||
|
||||
// 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"],
|
||||
},
|
||||
}),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user