Compare commits
5 Commits
e82ef76316
...
bb6d523abb
| Author | SHA1 | Date | |
|---|---|---|---|
| bb6d523abb | |||
| 09d3a7041a | |||
| 132e8d0146 | |||
| d0a0d08902 | |||
| 208cd615af |
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[javascriptreact]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[typescript]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[typescriptreact]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[json]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[graphql]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[handlebars]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
||||||
|
}
|
||||||
2
database/migrations/0025_amusing_sugar_man.sql
Normal file
2
database/migrations/0025_amusing_sugar_man.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
DROP TABLE "apiHits" CASCADE;--> statement-breakpoint
|
||||||
|
DROP TABLE "eom" CASCADE;
|
||||||
1056
database/migrations/meta/0025_snapshot.json
Normal file
1056
database/migrations/meta/0025_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -176,6 +176,13 @@
|
|||||||
"when": 1742408812383,
|
"when": 1742408812383,
|
||||||
"tag": "0024_curved_venom",
|
"tag": "0024_curved_venom",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 25,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742655504936,
|
||||||
|
"tag": "0025_amusing_sugar_man",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
16775
package-lock.json
generated
16775
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
155
package.json
155
package.json
@@ -1,81 +1,80 @@
|
|||||||
{
|
{
|
||||||
"name": "lstv2",
|
"name": "lstv2",
|
||||||
"version": "2.8.0",
|
"version": "2.8.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "concurrently -n \"server,frontend\" -c \"#007755,#2f6da3\" \"npm run dev:server\" \"cd frontend && npm run dev\"",
|
"dev": "concurrently -n \"server,frontend\" -c \"#007755,#2f6da3\" \"npm run dev:server\" \"cd frontend && npm run dev\"",
|
||||||
"dev:server": "dotenvx run -f .env -- tsx watch server/index.ts",
|
"dev:server": "dotenvx run -f .env -- tsx watch server/index.ts",
|
||||||
"dev:frontend": "cd frontend && npm run dev",
|
"dev:frontend": "cd frontend && npm run dev",
|
||||||
"dev:dbgen": " drizzle-kit generate --config=drizzle-dev.config.ts",
|
"dev:dbgen": " drizzle-kit generate --config=drizzle-dev.config.ts",
|
||||||
"dev:dbmigrate": " drizzle-kit migrate --config=drizzle-dev.config.ts",
|
"dev:dbmigrate": " drizzle-kit migrate --config=drizzle-dev.config.ts",
|
||||||
"build": "npm run build:server && npm run build:frontend",
|
"build": "npm run build:server && npm run build:frontend",
|
||||||
"build:server": "rimraf build && tsc --build && xcopy server\\scripts dist\\server\\scripts /E /I /Y && xcopy server\\services\\server\\utils\\serverData.json dist\\server\\services\\server\\utils /E /I /Y ",
|
"build:server": "rimraf dist && tsc --build && npm run copy:scripts",
|
||||||
"build:frontend": "cd frontend && npm run build",
|
"build:frontend": "cd frontend && npm run build",
|
||||||
"start": "set NODE_ENV=production && npm run start:server",
|
"copy:scripts": "tsx server/scripts/copyScripts.ts",
|
||||||
"start:server": "dotenvx run -f .env -- node dist/server/index.js",
|
"copy:servers": "xcopy server\\services\\server\\utils\\serverData.json dist\\server\\services\\server\\utils /E /I /Y",
|
||||||
"db:generate": "npx drizzle-kit generate",
|
"start": "set NODE_ENV=production && npm run start:server",
|
||||||
"db:migrate": "npx drizzle-kit push",
|
"start:server": "dotenvx run -f .env -- node dist/server/index.js",
|
||||||
"db:dev": "npm run build && npm run db:generate && npm run db:migrate",
|
"db:generate": "npx drizzle-kit generate",
|
||||||
"deploy": "standard-version --conventional-commits && npm run prodBuild",
|
"db:migrate": "npx drizzle-kit push",
|
||||||
"zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"",
|
"db:dev": "npm run build && npm run db:generate && npm run db:migrate",
|
||||||
"v1Build": "cd C:\\Users\\matthes01\\Documents\\logisticsSupportTool && npm run oldBuilder",
|
"deploy": "standard-version --conventional-commits && npm run prodBuild",
|
||||||
"prodBuild": "npm run v1Build && powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2\" && npm run zipServer",
|
"zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"",
|
||||||
"commit": "cz",
|
"v1Build": "cd C:\\Users\\matthes01\\Documents\\logisticsSupportTool && npm run oldBuilder",
|
||||||
"prodinstall": "npm i --omit=dev && npm run db:migrate",
|
"prodBuild": "npm run v1Build && powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2\" && npm run zipServer",
|
||||||
"checkupdates": "npx npm-check-updates"
|
"commit": "cz",
|
||||||
},
|
"prodinstall": "npm i --omit=dev && npm run db:migrate",
|
||||||
"dependencies": {
|
"checkupdates": "npx npm-check-updates"
|
||||||
"@dotenvx/dotenvx": "^1.39.0",
|
},
|
||||||
"@hono/node-server": "^1.14.0",
|
"config": {
|
||||||
"@hono/node-ws": "^1.1.0",
|
"commitizen": {
|
||||||
"@hono/zod-openapi": "^0.19.2",
|
"path": "./node_modules/cz-conventional-changelog"
|
||||||
"@scalar/hono-api-reference": "^0.7.2",
|
|
||||||
"@types/jsonwebtoken": "^9.0.9",
|
|
||||||
"@types/ws": "^8.18.0",
|
|
||||||
"adm-zip": "^0.5.16",
|
|
||||||
"axios": "^1.8.4",
|
|
||||||
"bcrypt": "^5.1.1",
|
|
||||||
"compression": "^1.8.0",
|
|
||||||
"cookie": "^1.0.2",
|
|
||||||
"date-fns": "^4.1.0",
|
|
||||||
"dotenv": "^16.4.7",
|
|
||||||
"drizzle-kit": "^0.30.5",
|
|
||||||
"drizzle-orm": "^0.41.0",
|
|
||||||
"drizzle-zod": "^0.7.0",
|
|
||||||
"fast-xml-parser": "^5.0.9",
|
|
||||||
"jsonwebtoken": "^9.0.2",
|
|
||||||
"mssql": "^11.0.1",
|
|
||||||
"nodemailer": "^6.10.0",
|
|
||||||
"nodemailer-express-handlebars": "^7.0.0",
|
|
||||||
"pg": "^8.14.1",
|
|
||||||
"pino": "^9.6.0",
|
|
||||||
"pino-abstract-transport": "^2.0.0",
|
|
||||||
"pino-pretty": "^13.0.0",
|
|
||||||
"postgres": "^3.4.5",
|
|
||||||
"zod": "^3.24.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/adm-zip": "^0.5.7",
|
|
||||||
"@types/bcrypt": "^5.0.2",
|
|
||||||
"@types/js-cookie": "^3.0.6",
|
|
||||||
"@types/mssql": "^9.1.7",
|
|
||||||
"@types/node": "^22.13.11",
|
|
||||||
"@types/pg": "^8.11.11",
|
|
||||||
"concurrently": "^9.1.2",
|
|
||||||
"cz-conventional-changelog": "^3.3.0",
|
|
||||||
"dotenv": "^16.4.7",
|
|
||||||
"rimraf": "^6.0.1",
|
|
||||||
"standard-version": "^9.5.0",
|
|
||||||
"tsx": "^4.19.3",
|
|
||||||
"typescript": "~5.8.2"
|
|
||||||
},
|
|
||||||
"config": {
|
|
||||||
"commitizen": {
|
|
||||||
"path": "./node_modules/cz-conventional-changelog"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"admConfig": {
|
|
||||||
"build": 47,
|
|
||||||
"oldBuild": "backend-0.1.3.zip"
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"admConfig": {
|
||||||
|
"build": 47,
|
||||||
|
"oldBuild": "backend-0.1.3.zip"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/adm-zip": "^0.5.7",
|
||||||
|
"@types/bcrypt": "^5.0.2",
|
||||||
|
"@types/fs-extra": "^11.0.4",
|
||||||
|
"@types/js-cookie": "^3.0.6",
|
||||||
|
"@types/mssql": "^9.1.7",
|
||||||
|
"@types/node": "^22.13.11",
|
||||||
|
"@types/pg": "^8.11.11",
|
||||||
|
"@types/ws": "^8.18.0",
|
||||||
|
"concurrently": "^9.1.2",
|
||||||
|
"cz-conventional-changelog": "^3.3.0",
|
||||||
|
"drizzle-kit": "^0.30.5",
|
||||||
|
"fs-extra": "^11.3.0",
|
||||||
|
"standard-version": "^9.5.0",
|
||||||
|
"tsx": "^4.19.3",
|
||||||
|
"typescript": "^5.8.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@dotenvx/dotenvx": "^1.39.0",
|
||||||
|
"@hono/node-server": "^1.14.0",
|
||||||
|
"@hono/zod-openapi": "^0.19.2",
|
||||||
|
"@scalar/hono-api-reference": "^0.7.2",
|
||||||
|
"@types/jsonwebtoken": "^9.0.9",
|
||||||
|
"adm-zip": "^0.5.16",
|
||||||
|
"axios": "^1.8.4",
|
||||||
|
"bcryptjs": "^3.0.2",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
|
"drizzle-orm": "^0.41.0",
|
||||||
|
"drizzle-zod": "^0.7.0",
|
||||||
|
"fast-xml-parser": "^5.0.9",
|
||||||
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"mssql": "^11.0.1",
|
||||||
|
"nodemailer": "^6.10.0",
|
||||||
|
"nodemailer-express-handlebars": "^7.0.0",
|
||||||
|
"pg": "^8.14.1",
|
||||||
|
"pino": "^9.6.0",
|
||||||
|
"pino-abstract-transport": "^2.0.0",
|
||||||
|
"pino-pretty": "^13.0.0",
|
||||||
|
"postgres": "^3.4.5",
|
||||||
|
"rimraf": "^6.0.1",
|
||||||
|
"zod": "^3.24.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
192
server/index.ts
192
server/index.ts
@@ -1,11 +1,11 @@
|
|||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||||
import {serve} from "@hono/node-server";
|
import { serve } from "@hono/node-server";
|
||||||
import {OpenAPIHono} from "@hono/zod-openapi";
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {proxy} from "hono/proxy";
|
import { proxy } from "hono/proxy";
|
||||||
import {serveStatic} from "@hono/node-server/serve-static";
|
import { serveStatic } from "@hono/node-server/serve-static";
|
||||||
import {logger} from "hono/logger";
|
import { logger } from "hono/logger";
|
||||||
import {cors} from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import {createLog} from "./services/logger/logger.js";
|
import { createLog } from "./services/logger/logger.js";
|
||||||
|
|
||||||
// custom routes
|
// custom routes
|
||||||
import scalar from "./services/general/route/scalar.js";
|
import scalar from "./services/general/route/scalar.js";
|
||||||
@@ -19,11 +19,9 @@ import rfid from "./services/rfid/rfidService.js";
|
|||||||
import printers from "./services/printers/printerService.js";
|
import printers from "./services/printers/printerService.js";
|
||||||
import loggerService from "./services/logger/loggerService.js";
|
import loggerService from "./services/logger/loggerService.js";
|
||||||
import ocpService from "./services/ocp/ocpService.js";
|
import ocpService from "./services/ocp/ocpService.js";
|
||||||
import {db} from "../database/dbclient.js";
|
import { db } from "../database/dbclient.js";
|
||||||
import {settings} from "../database/schema/settings.js";
|
import { settings } from "../database/schema/settings.js";
|
||||||
import {count, eq} from "drizzle-orm";
|
import { count } from "drizzle-orm";
|
||||||
import {createNodeWebSocket} from "@hono/node-ws";
|
|
||||||
import {streamSSE} from "hono/streaming";
|
|
||||||
|
|
||||||
// create the main prodlogin here
|
// create the main prodlogin here
|
||||||
const username = "lst_user";
|
const username = "lst_user";
|
||||||
@@ -31,97 +29,66 @@ const password = "Alpla$$Prod";
|
|||||||
export const lstAuth = btoa(`${username}:${password}`);
|
export const lstAuth = btoa(`${username}:${password}`);
|
||||||
|
|
||||||
// checking to make sure we have the settings intialized
|
// checking to make sure we have the settings intialized
|
||||||
const serverIntialized = await db.select({count: count()}).from(settings);
|
const serverIntialized = await db.select({ count: count() }).from(settings);
|
||||||
export const installed = serverIntialized[0].count === 0 && process.env.NODE_ENV !== "development" ? false : true;
|
export const installed =
|
||||||
|
serverIntialized[0].count === 0 && process.env.NODE_ENV !== "development"
|
||||||
|
? false
|
||||||
|
: true;
|
||||||
createLog("info", "LST", "server", `Server is installed: ${installed}`);
|
createLog("info", "LST", "server", `Server is installed: ${installed}`);
|
||||||
|
|
||||||
const app = new OpenAPIHono({strict: false});
|
const app = new OpenAPIHono({ strict: false });
|
||||||
export const {injectWebSocket, upgradeWebSocket} = createNodeWebSocket({app});
|
|
||||||
|
|
||||||
// middle ware
|
// middle ware
|
||||||
app.use("*", logger());
|
app.use("*", logger());
|
||||||
app.use(
|
app.use(
|
||||||
"*",
|
"*",
|
||||||
cors({
|
cors({
|
||||||
origin: "*", // Allow all origins
|
origin: "*", // Allow all origins
|
||||||
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
||||||
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
||||||
//exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
//exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
||||||
credentials: true, // Allow credentials if needed
|
credentials: true, // Allow credentials if needed
|
||||||
maxAge: 600,
|
maxAge: 600,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Middleware to normalize route case
|
// Middleware to normalize route case
|
||||||
app.use("*", async (c, next) => {
|
app.use("*", async (c, next) => {
|
||||||
const lowercasedUrl = c.req.url.toLowerCase();
|
const lowercasedUrl = c.req.url.toLowerCase();
|
||||||
//console.log("Incoming Request:", c.req.url, c.req.method);
|
//console.log("Incoming Request:", c.req.url, c.req.method);
|
||||||
// If the URL is already lowercase, continue as usual
|
// If the URL is already lowercase, continue as usual
|
||||||
if (c.req.url === lowercasedUrl) {
|
if (c.req.url === lowercasedUrl) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, re-route internally
|
// Otherwise, re-route internally
|
||||||
return c.redirect(lowercasedUrl, 308); // 308 preserves the HTTP method
|
return c.redirect(lowercasedUrl, 308); // 308 preserves the HTTP method
|
||||||
});
|
});
|
||||||
|
|
||||||
app.doc("/api/ref", {
|
app.doc("/api/ref", {
|
||||||
openapi: "3.0.0",
|
openapi: "3.0.0",
|
||||||
info: {
|
info: {
|
||||||
version: "2.0.0",
|
version: "2.0.0",
|
||||||
title: "LST API",
|
title: "LST API",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get(
|
|
||||||
"/api/log",
|
|
||||||
// upgradeWebSocket(() => {
|
|
||||||
// return {
|
|
||||||
// onMessage(event, ws) {
|
|
||||||
// console.log(`Message from client: ${event.data}`);
|
|
||||||
// ws.send("Hello from server!");
|
|
||||||
// },
|
|
||||||
// onClose: () => {
|
|
||||||
// console.log("Connection closed");
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
// })
|
|
||||||
async (c) => {
|
|
||||||
let id = 0;
|
|
||||||
let running = true;
|
|
||||||
return streamSSE(c, async (stream) => {
|
|
||||||
while (running) {
|
|
||||||
const message = `It is ${new Date().toISOString()}`;
|
|
||||||
await stream.writeSSE({
|
|
||||||
data: message,
|
|
||||||
event: "time-update",
|
|
||||||
id: String(id++),
|
|
||||||
});
|
|
||||||
await stream.sleep(1000);
|
|
||||||
if (id === 5) {
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
scalar,
|
scalar,
|
||||||
auth,
|
auth,
|
||||||
// apiHits,
|
// apiHits,
|
||||||
system,
|
system,
|
||||||
tcpServer,
|
tcpServer,
|
||||||
sqlService,
|
sqlService,
|
||||||
logistics,
|
logistics,
|
||||||
rfid,
|
rfid,
|
||||||
printers,
|
printers,
|
||||||
loggerService,
|
loggerService,
|
||||||
ocpService,
|
ocpService,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const appRoutes = routes.forEach((route) => {
|
const appRoutes = routes.forEach((route) => {
|
||||||
app.route("/api/", route);
|
app.route("/api/", route);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.route("/ocme/", ocme);
|
app.route("/ocme/", ocme);
|
||||||
@@ -154,48 +121,55 @@ app.route("/ocme/", ocme);
|
|||||||
//---------------------------------------------------\\
|
//---------------------------------------------------\\
|
||||||
|
|
||||||
// the catch all api route
|
// the catch all api route
|
||||||
app.all("/api/*", (c) => c.json({error: "API route not found"}, 404));
|
app.all("/api/*", (c) => c.json({ error: "API route not found" }, 404));
|
||||||
|
|
||||||
// front end static files
|
// front end static files
|
||||||
app.use("/*", serveStatic({root: "./frontend/dist"}));
|
app.use("/*", serveStatic({ root: "./frontend/dist" }));
|
||||||
app.use("*", serveStatic({path: "./frontend/dist/index.html"}));
|
app.use("*", serveStatic({ path: "./frontend/dist/index.html" }));
|
||||||
|
|
||||||
// Handle app exit signals
|
// Handle app exit signals
|
||||||
process.on("SIGINT", async () => {
|
process.on("SIGINT", async () => {
|
||||||
console.log("\nGracefully shutting down...");
|
console.log("\nGracefully shutting down...");
|
||||||
//await closePool();
|
//await closePool();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGTERM", async () => {
|
process.on("SIGTERM", async () => {
|
||||||
console.log("Received termination signal, closing database...");
|
console.log("Received termination signal, closing database...");
|
||||||
//await closePool();
|
//await closePool();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("uncaughtException", async (err) => {
|
process.on("uncaughtException", async (err) => {
|
||||||
console.log("Uncaught Exception:", err);
|
console.log("Uncaught Exception:", err);
|
||||||
//await closePool();
|
//await closePool();
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("beforeExit", async () => {
|
process.on("beforeExit", async () => {
|
||||||
console.log("Process is about to exit...");
|
console.log("Process is about to exit...");
|
||||||
//await closePool();
|
//await closePool();
|
||||||
});
|
});
|
||||||
|
|
||||||
const port = process.env.NODE_ENV === "development" ? process.env.VITE_SERVER_PORT : process.env.PROD_PORT;
|
const port =
|
||||||
injectWebSocket(
|
process.env.NODE_ENV === "development"
|
||||||
serve(
|
? process.env.VITE_SERVER_PORT
|
||||||
{
|
: process.env.PROD_PORT;
|
||||||
fetch: app.fetch,
|
|
||||||
port: Number(port),
|
serve(
|
||||||
hostname: "0.0.0.0",
|
{
|
||||||
},
|
fetch: app.fetch,
|
||||||
(info) => {
|
port: Number(port),
|
||||||
createLog("info", "LST", "server", `Server is running on http://${info.address}:${info.port}`);
|
hostname: "0.0.0.0",
|
||||||
}
|
},
|
||||||
)
|
(info) => {
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"LST",
|
||||||
|
"server",
|
||||||
|
`Server is running on http://${info.address}:${info.port}`
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export type AppRoutes = typeof appRoutes;
|
export type AppRoutes = typeof appRoutes;
|
||||||
|
|||||||
65
server/scripts/copyScripts.ts
Normal file
65
server/scripts/copyScripts.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import fs from "fs-extra";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
// Get the current directory of the module
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
const sourceDir = path.join(__dirname, "/");
|
||||||
|
const destDir = path.join("./", "dist", "server", "scripts");
|
||||||
|
|
||||||
|
// Copy only .ps1 files
|
||||||
|
fs.readdir(sourceDir)
|
||||||
|
.then((files) => {
|
||||||
|
files.forEach((file) => {
|
||||||
|
if (path.extname(file) === ".ps1") {
|
||||||
|
const sourceFile = path.join(sourceDir, file);
|
||||||
|
const destFile = path.join(destDir, file);
|
||||||
|
|
||||||
|
// Copy each .ps1 file
|
||||||
|
fs.copy(sourceFile, destFile)
|
||||||
|
.then(() => {
|
||||||
|
console.log(`Copied: ${file}`);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(`Error copying file: ${file}`, err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error("Error reading source directory:", err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Paths for source and destination of serverData.json
|
||||||
|
const sourceFile = path.join(
|
||||||
|
"./",
|
||||||
|
"server",
|
||||||
|
"services",
|
||||||
|
"server",
|
||||||
|
"utils",
|
||||||
|
"serverData.json"
|
||||||
|
);
|
||||||
|
const serverDataDest = path.join(
|
||||||
|
"./",
|
||||||
|
"dist",
|
||||||
|
"server",
|
||||||
|
"services",
|
||||||
|
"server",
|
||||||
|
"utils"
|
||||||
|
);
|
||||||
|
const destFile = path.join(serverDataDest, "serverData.json");
|
||||||
|
|
||||||
|
// Ensure the destination directory exists
|
||||||
|
fs.ensureDir(destDir)
|
||||||
|
.then(() => {
|
||||||
|
// Copy the serverData.json file
|
||||||
|
return fs.copy(sourceFile, destFile);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log("serverData.json copied successfully!");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error("Error copying serverData.json:", err);
|
||||||
|
});
|
||||||
@@ -1,37 +1,56 @@
|
|||||||
# Install
|
# Install
|
||||||
|
|
||||||
## Files needed to be downloaded before install.
|
## Files needed to be downloaded before install.
|
||||||
|
|
||||||
### To run the server
|
### To run the server
|
||||||
* [PostgresSQL](https://www.postgresql.org/download/windows/) - current version using is 17
|
|
||||||
* [NodeJS](https://nodejs.org)
|
- [PostgresSQL](https://www.postgresql.org/download/windows/) - current version using is 17
|
||||||
* [NSSM](https://nssm.cc/)
|
- [NodeJS](https://nodejs.org)
|
||||||
|
- [NSSM](https://nssm.cc/)
|
||||||
|
|
||||||
### To manage the server
|
### To manage the server
|
||||||
* [VSCODE](https://code.visualstudio.com/)
|
|
||||||
* [Postman](https://www.postman.com/downloads/)
|
- [VSCODE](https://code.visualstudio.com/)
|
||||||
|
- [Postman](https://www.postman.com/downloads/)
|
||||||
|
|
||||||
## Creating directories needed
|
## Creating directories needed
|
||||||
* Create a new folder where we will host the server files.
|
|
||||||
* Copy the nssm.exe into this folder
|
- Create a new folder where we will host the server files.
|
||||||
* Copy the build files to the server (only needed for intial install).
|
- Copy the nssm.exe into this folder
|
||||||
* This will house all the compiles and minified files needed to start the server up, this includes the frontend.
|
- Copy the build files to the server (only needed for intial install).
|
||||||
* Save the nssm.exe into this folder as well, this will be used to control the service.
|
- This will house all the compiles and minified files needed to start the server up, this includes the frontend.
|
||||||
|
- Save the nssm.exe into this folder as well, this will be used to control the service.
|
||||||
|
|
||||||
## Do the intial install
|
## Do the intial install
|
||||||
|
|
||||||
### DB instal setup
|
### DB instal setup
|
||||||
|
|
||||||
1. Install postgres
|
1. Install postgres
|
||||||
2. Open pgAdmin
|
2. Open pgAdmin
|
||||||
3. create a new Database named lst_db
|
3. create a new Database named lst_db
|
||||||
|
|
||||||
### Intial server setup
|
### Intial server setup
|
||||||
|
|
||||||
1. Open VSCode and navigate to the folder where you extracted the files.
|
1. Open VSCode and navigate to the folder where you extracted the files.
|
||||||
2. Click trusted when it pops up.
|
2. Click trusted when it pops up.
|
||||||
3. Open a terminal window inside vscode.
|
3. Open a terminal window inside vscode.
|
||||||
4. Run the install script this will install all dependaceys needed as well as do all the database migrations
|
4. Run the install script this will install all dependaceys needed as well as do all the database migrations
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run prodinstall
|
npm run prodinstall
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Next we want to do an intial build for the db
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
### Create the .env file
|
### Create the .env file
|
||||||
|
|
||||||
In the root of the folder create a new .env file
|
In the root of the folder create a new .env file
|
||||||
add in the below and change each setting area that says change me to something that suits your needs
|
add in the below and change each setting area that says change me to something that suits your needs
|
||||||
|
|
||||||
```env
|
```env
|
||||||
# PORTS
|
# PORTS
|
||||||
# To keep it all simple we will pass VITE to the ports that are used on both sides.
|
# To keep it all simple we will pass VITE to the ports that are used on both sides.
|
||||||
@@ -39,7 +58,9 @@ VITE_SERVER_PORT=4400
|
|||||||
|
|
||||||
# logLevel
|
# logLevel
|
||||||
LOG_LEVEL=debug
|
LOG_LEVEL=debug
|
||||||
|
PROD_PORT=4000
|
||||||
|
# DUE to lstv1 we need 3000
|
||||||
|
SEC_PORT=3000
|
||||||
# Auth stuff
|
# Auth stuff
|
||||||
SALTING=12
|
SALTING=12
|
||||||
SECRET=CHANGEME
|
SECRET=CHANGEME
|
||||||
@@ -64,62 +85,80 @@ MAXLOTS=3
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Run the start command to get all the basic settings and modules installed
|
### Run the start command to get all the basic settings and modules installed
|
||||||
|
|
||||||
1. Run the below
|
1. Run the below
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will start up the server and seed the database.
|
This command will start up the server and seed the database.
|
||||||
* Settings will be set here.
|
|
||||||
* All modules will be added.
|
- Settings will be set here.
|
||||||
|
- All modules will be added.
|
||||||
|
|
||||||
2. Press CTRL + C to stop the server.
|
2. Press CTRL + C to stop the server.
|
||||||
3. Reopen postgres and review the settings make the changes to match the server your going to be running in.
|
3. Reopen postgres and review the settings make the changes to match the server your going to be running in.
|
||||||
* Change the server
|
- Change the server
|
||||||
* change the dbServer
|
- change the dbServer
|
||||||
* change plantToken
|
- change plantToken
|
||||||
* then the remaining settings confirm if you need on or want to leave as default.
|
- then the remaining settings confirm if you need on or want to leave as default.
|
||||||
|
|
||||||
### Creating first user.
|
### Creating first user.
|
||||||
|
|
||||||
1. Start the server back up.
|
1. Start the server back up.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Open http://[SERVER]:[PORT]/api/docs or postman and create a user.
|
2. Open http://[SERVER]:[PORT]/api/docs or postman and create a user.
|
||||||
* Please do not try to manually enter a new user this is due to how the password is hashed, as well as setting systemAdmin for the first user.
|
- Please do not try to manually enter a new user this is due to how the password is hashed, as well as setting systemAdmin for the first user.
|
||||||
* Change the server and port to what you changed in the DB.
|
- Change the server and port to what you changed in the DB.
|
||||||
3. Stop the server again with CTRL + C.
|
3. Stop the server again with CTRL + C.
|
||||||
|
|
||||||
### Running as a serivice.
|
### Running as a serivice.
|
||||||
|
|
||||||
You want to CD into the scripts folder.
|
You want to CD into the scripts folder.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd .\dist\server\scripts\
|
cd .\dist\server\scripts\
|
||||||
```
|
```
|
||||||
|
|
||||||
Next use the example command below to get the service up and running.
|
Next use the example command below to get the service up and running.
|
||||||
* Options legend
|
|
||||||
* serviceName = not recommended to change to reduce issues with the update process
|
- Options legend
|
||||||
* option = use install for the install, but you can use this script later to stop, start, restart the service.
|
- serviceName = not recommended to change to reduce issues with the update process
|
||||||
* appPath = where did you extract the server files
|
- option = use install for the install, but you can use this script later to stop, start, restart the service.
|
||||||
* description = no need to change this unless you want it to be something else
|
- appPath = where did you extract the server files
|
||||||
* command = do not change this unless you know what your doing and really need to change this.
|
- description = no need to change this unless you want it to be something else
|
||||||
|
- command = do not change this unless you know what your doing and really need to change this.
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
.\services.ps1 -serviceName "LSTV2" -option "install" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
.\services.ps1 -serviceName "LSTV2" -option "install" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
||||||
```
|
```
|
||||||
|
|
||||||
# Migrating From V1 to V2
|
# Migrating From V1 to V2
|
||||||
|
|
||||||
## User migration
|
## User migration
|
||||||
|
|
||||||
1. Open the sqlite db and export to sql the users table
|
1. Open the sqlite db and export to sql the users table
|
||||||
2. OPen the sql in notepad++ or your editor of choice and change the query to be similar to below.
|
2. OPen the sql in notepad++ or your editor of choice and change the query to be similar to below.
|
||||||
* we only need to have save the username, role, email, password
|
- we only need to have save the username, role, email, password
|
||||||
|
|
||||||
An example new query will look like
|
An example new query will look like
|
||||||
* Below is how it looks when exported from sqlite
|
|
||||||
|
- Below is how it looks when exported from sqlite
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
INSERT INTO "User" ("id", "username", "email", "role", "password", "passwordToken", "tokenExpire", "active", "pinCode", "lastLogin", "add_user", "add_date", "upd_user", "upd_date") VALUES
|
INSERT INTO "User" ("id", "username", "email", "role", "password", "passwordToken", "tokenExpire", "active", "pinCode", "lastLogin", "add_user", "add_date", "upd_user", "upd_date") VALUES
|
||||||
(1, 'matthes01', 'blake.matthes@alpla.com', 'admin', 'JDJiJDEMUJEdGtL', NULL, NULL, '1', NULL, '1721075647687', 'LST_System', '1721075647687', 'LST_System', '1721075647687');
|
(1, 'matthes01', 'blake.matthes@alpla.com', 'admin', 'JDJiJDEMUJEdGtL', NULL, NULL, '1', NULL, '1721075647687', 'LST_System', '1721075647687', 'LST_System', '1721075647687');
|
||||||
```
|
```
|
||||||
|
|
||||||
The way we want to put recreate the query to work with the new db
|
The way we want to put recreate the query to work with the new db
|
||||||
* Below example
|
|
||||||
|
- Below example
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
INSERT INTO "users" ("username", "email", "role", "password") VALUES
|
INSERT INTO "users" ("username", "email", "role", "password") VALUES
|
||||||
('matthes01','blake.matthes@alpla.com','admin','JDJiJDE1FuNFpkYlk4NGdHUXpEMzlHR1BD'),
|
('matthes01','blake.matthes@alpla.com','admin','JDJiJDE1FuNFpkYlk4NGdHUXpEMzlHR1BD'),
|
||||||
@@ -127,11 +166,12 @@ INSERT INTO "users" ("username", "email", "role", "password") VALUES
|
|||||||
('brandon001','brandon.harry@alpla.com','manager','wdm1RSXJlZnJDYTZP');
|
('brandon001','brandon.harry@alpla.com','manager','wdm1RSXJlZnJDYTZP');
|
||||||
;
|
;
|
||||||
```
|
```
|
||||||
* You could have many users and just add like above with the identical info from the db
|
|
||||||
|
|
||||||
|
- You could have many users and just add like above with the identical info from the db
|
||||||
|
|
||||||
## Running v1 along Side V2 for the interm
|
## Running v1 along Side V2 for the interm
|
||||||
* change v2 prod port to 4000 in the env and db
|
|
||||||
* change v1 env to 4400 in the env. and in the db you will need to change the auth server to 4000 and the serverPort to 4400
|
- change v2 prod port to 4000 in the env and db
|
||||||
|
- change v1 env to 4400 in the env. and in the db you will need to change the auth server to 4000 and the serverPort to 4400
|
||||||
|
|
||||||
This will change so that v2 is the main server now, this is needed for ocme mainly.
|
This will change so that v2 is the main server now, this is needed for ocme mainly.
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcryptjs";
|
||||||
|
export const checkPassword = async (
|
||||||
|
currentPassword: string,
|
||||||
|
dbPassword: string
|
||||||
|
) => {
|
||||||
|
let decyptPass = "";
|
||||||
|
try {
|
||||||
|
decyptPass = atob(dbPassword);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
// encypt password
|
||||||
|
const pass: string | undefined = process.env.SECRET;
|
||||||
|
|
||||||
export const checkPassword = async (currentPassword: string, dbPassword: string) => {
|
const checked = bcrypt.compareSync(pass + currentPassword, decyptPass);
|
||||||
let decyptPass = "";
|
|
||||||
try {
|
|
||||||
decyptPass = atob(dbPassword);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
// encypt password
|
|
||||||
const pass: string | undefined = process.env.SECRET;
|
|
||||||
|
|
||||||
const checked = bcrypt.compareSync(pass + currentPassword, decyptPass);
|
return checked;
|
||||||
|
|
||||||
return checked;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
export const createPassword = async (password: string) => {
|
export const createPassword = async (password: string) => {
|
||||||
// encypt password
|
// encypt password
|
||||||
let pass: string | undefined = process.env.SECRET;
|
let pass: string | undefined = process.env.SECRET;
|
||||||
let salt: string | undefined = process.env.SALTING;
|
let salt: string | undefined = process.env.SALTING;
|
||||||
|
|
||||||
if (!pass || !salt) {
|
if (!pass || !salt) {
|
||||||
pass = "error";
|
pass = "error";
|
||||||
} else {
|
} else {
|
||||||
pass = bcrypt.hashSync(pass + password, parseInt(salt));
|
pass = bcrypt.hashSync(pass + password, parseInt(salt));
|
||||||
|
|
||||||
pass = btoa(pass);
|
pass = btoa(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "hono/jsx",
|
"jsxImportSource": "hono/jsx",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
|
"include": ["server", "scripts/**/*.ts"],
|
||||||
"exclude": ["node_modules", "frontend", "dist", "testFiles"]
|
"exclude": ["node_modules", "frontend", "dist", "testFiles"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user