refactor(old app): login migration to new app
This commit is contained in:
@@ -1,35 +1,34 @@
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
|
||||
import { serve } from "@hono/node-server";
|
||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
|
||||
import { serveStatic } from "@hono/node-server/serve-static";
|
||||
import { logger } from "hono/logger";
|
||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { cors } from "hono/cors";
|
||||
import { createLog } from "./services/logger/logger.js";
|
||||
|
||||
import { logger } from "hono/logger";
|
||||
import os from "os";
|
||||
import auth from "./services/auth/authService.js";
|
||||
import dataMart from "./services/dataMart/dataMartService.js";
|
||||
import eom from "./services/eom/eomService.js";
|
||||
// custom routes
|
||||
import scalar from "./services/general/route/scalar.js";
|
||||
import system from "./services/server/systemServer.js";
|
||||
import auth from "./services/auth/authService.js";
|
||||
import tcpServer from "./services/tcpServer/tcpServer.js";
|
||||
import ocme from "./services/ocme/ocmeService.js";
|
||||
import sqlService from "./services/sqlServer/sqlService.js";
|
||||
import logistics from "./services/logistics/logisticsService.js";
|
||||
import rfid from "./services/rfid/rfidService.js";
|
||||
import printers from "./services/printers/printerService.js";
|
||||
import { createLog } from "./services/logger/logger.js";
|
||||
import loggerService from "./services/logger/loggerService.js";
|
||||
import ocpService from "./services/ocp/ocpService.js";
|
||||
import os from "os";
|
||||
import logistics from "./services/logistics/logisticsService.js";
|
||||
import { sendEmail } from "./services/notifications/controller/sendMail.js";
|
||||
import notify from "./services/notifications/notifyService.js";
|
||||
import eom from "./services/eom/eomService.js";
|
||||
import dataMart from "./services/dataMart/dataMartService.js";
|
||||
import qualityRequest from "./services/quality/qualityService.js";
|
||||
import ocme from "./services/ocme/ocmeService.js";
|
||||
import ocpService from "./services/ocp/ocpService.js";
|
||||
import printers from "./services/printers/printerService.js";
|
||||
import produser from "./services/prodUser/prodUser.js";
|
||||
import qualityRequest from "./services/quality/qualityService.js";
|
||||
import rfid from "./services/rfid/rfidService.js";
|
||||
import {
|
||||
getSettings,
|
||||
serverSettings,
|
||||
getSettings,
|
||||
serverSettings,
|
||||
} from "./services/server/controller/settings/getSettings.js";
|
||||
import system from "./services/server/systemServer.js";
|
||||
import sqlService from "./services/sqlServer/sqlService.js";
|
||||
import tcpServer from "./services/tcpServer/tcpServer.js";
|
||||
|
||||
// create the main prodlogin here
|
||||
const username = "lst_user";
|
||||
@@ -48,28 +47,33 @@ export const lstAuth = btoa(`${username}:${password}`);
|
||||
const serverIntialized: any = await getSettings();
|
||||
|
||||
export const installed =
|
||||
serverIntialized.length === 0 && process.env.NODE_ENV !== "development"
|
||||
? false
|
||||
: true;
|
||||
serverIntialized.length === 0 && process.env.NODE_ENV !== "development"
|
||||
? false
|
||||
: true;
|
||||
createLog("info", "LST", "server", `Server is installed: ${installed}`);
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
// middle ware
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
app.use("*", logger());
|
||||
app.use("*", logger());
|
||||
}
|
||||
|
||||
app.use(
|
||||
"*",
|
||||
cors({
|
||||
origin: "*", // Allow all origins
|
||||
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
||||
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
||||
//exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
||||
credentials: true, // Allow credentials if needed
|
||||
maxAge: 600,
|
||||
})
|
||||
"*",
|
||||
cors({
|
||||
origin: [
|
||||
"http://localhost:3000",
|
||||
"http://localhost:5173",
|
||||
"http://localhost:4000",
|
||||
"http://localhost:4200",
|
||||
], // Allow all origins
|
||||
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
||||
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
||||
//exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
||||
credentials: true, // Allow credentials if needed
|
||||
maxAge: 600,
|
||||
}),
|
||||
);
|
||||
|
||||
// Middleware to normalize route case
|
||||
@@ -86,34 +90,34 @@ app.use(
|
||||
// });
|
||||
|
||||
app.doc("/api/ref", {
|
||||
openapi: "3.0.0",
|
||||
info: {
|
||||
version: "2.0.0",
|
||||
title: "LST API",
|
||||
},
|
||||
openapi: "3.0.0",
|
||||
info: {
|
||||
version: "2.0.0",
|
||||
title: "LST API",
|
||||
},
|
||||
});
|
||||
|
||||
const routes = [
|
||||
scalar,
|
||||
auth,
|
||||
// apiHits,
|
||||
system,
|
||||
tcpServer,
|
||||
sqlService,
|
||||
logistics,
|
||||
rfid,
|
||||
printers,
|
||||
loggerService,
|
||||
ocpService,
|
||||
notify,
|
||||
eom,
|
||||
dataMart,
|
||||
qualityRequest,
|
||||
produser,
|
||||
scalar,
|
||||
auth,
|
||||
// apiHits,
|
||||
system,
|
||||
tcpServer,
|
||||
sqlService,
|
||||
logistics,
|
||||
rfid,
|
||||
printers,
|
||||
loggerService,
|
||||
ocpService,
|
||||
notify,
|
||||
eom,
|
||||
dataMart,
|
||||
qualityRequest,
|
||||
produser,
|
||||
] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/api/", route);
|
||||
app.route("/api/", route);
|
||||
});
|
||||
|
||||
app.route("/ocme/", ocme);
|
||||
@@ -154,60 +158,60 @@ app.use("*", serveStatic({ path: "./frontend/dist/index.html" }));
|
||||
|
||||
// Handle app exit signals
|
||||
process.on("SIGINT", async () => {
|
||||
console.log("\nGracefully shutting down...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
console.log("\nGracefully shutting down...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", async () => {
|
||||
console.log("Received termination signal, closing database...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
console.log("Received termination signal, closing database...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("uncaughtException", async (err) => {
|
||||
console.log("Uncaught Exception:", err);
|
||||
//await closePool();
|
||||
const emailData = {
|
||||
email: "blake.matthes@alpla.com", // should be moved to the db so it can be reused.
|
||||
subject: `${os.hostname()} has just encountered a crash.`,
|
||||
template: "serverCrash",
|
||||
context: {
|
||||
error: err,
|
||||
plant: `${os.hostname()}`,
|
||||
},
|
||||
};
|
||||
console.log("Uncaught Exception:", err);
|
||||
//await closePool();
|
||||
const emailData = {
|
||||
email: "blake.matthes@alpla.com", // should be moved to the db so it can be reused.
|
||||
subject: `${os.hostname()} has just encountered a crash.`,
|
||||
template: "serverCrash",
|
||||
context: {
|
||||
error: err,
|
||||
plant: `${os.hostname()}`,
|
||||
},
|
||||
};
|
||||
|
||||
await sendEmail(emailData);
|
||||
//process.exit(1);
|
||||
await sendEmail(emailData);
|
||||
//process.exit(1);
|
||||
});
|
||||
|
||||
process.on("beforeExit", async () => {
|
||||
console.log("Process is about to exit...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
console.log("Process is about to exit...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
const port =
|
||||
process.env.NODE_ENV === "development"
|
||||
? process.env.VITE_SERVER_PORT
|
||||
: process.env.PROD_PORT;
|
||||
process.env.NODE_ENV === "development"
|
||||
? process.env.VITE_SERVER_PORT
|
||||
: process.env.PROD_PORT;
|
||||
|
||||
const ocmeport = process.env.OCME_PORT;
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(port),
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog(
|
||||
"info",
|
||||
"LST",
|
||||
"server",
|
||||
`Server is running on http://${info.address}:${info.port}`
|
||||
);
|
||||
}
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(port),
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog(
|
||||
"info",
|
||||
"LST",
|
||||
"server",
|
||||
`Server is running on http://${info.address}:${info.port}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -217,21 +221,21 @@ serve(
|
||||
const setting = serverSettings;
|
||||
const isActive = setting.filter((n) => n.name === "ocmeService");
|
||||
if (ocmeport && isActive[0]?.value === "1") {
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(ocmeport),
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog(
|
||||
"info",
|
||||
"LST",
|
||||
"server",
|
||||
`Ocme section is listening on http://${info.address}:${info.port}`
|
||||
);
|
||||
}
|
||||
);
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(ocmeport),
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog(
|
||||
"info",
|
||||
"LST",
|
||||
"server",
|
||||
`Ocme section is listening on http://${info.address}:${info.port}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export type AppRoutes = typeof appRoutes;
|
||||
|
||||
Reference in New Issue
Block a user