intials app

This commit is contained in:
2025-08-26 15:25:09 -05:00
parent 10b56bf31f
commit d3fd5aa653
59 changed files with 22132 additions and 29 deletions

View File

@@ -0,0 +1 @@
export const printers = () => {};

View File

@@ -0,0 +1,15 @@
import type { Express, Request, Response } from "express";
import healthRoutes from './routes/healthRoutes.js'
export const setupRoutes = (app: Express, basePath: string) => {
// Root / health check
app.use(basePath + "/health", healthRoutes);
// Fallback 404 handler
app.use((req: Request, res: Response) => {
res.status(404).json({ error: "Not Found" });
});
}

View File

@@ -0,0 +1,10 @@
import { Router } from "express";
const router = Router();
// GET /health
router.get("/", (req, res) => {
res.json({ status: "ok", uptime: process.uptime() });
});
export default router;

67
app/src/main.ts Normal file
View File

@@ -0,0 +1,67 @@
import express from "express";
import morgan from "morgan";
import { createServer } from "http";
import { setupRoutes } from "./internal/routerHandler/routeHandler.js";
import { printers } from "./internal/ocp/printers/printers.js";
import path, { dirname, join } from "path";
import { fileURLToPath } from "url";
const PORT = Number(process.env.VITE_PORT) || 4200;
const main = async () => {
// base path
let basePath: string = "";
if (process.env.NODE_ENV?.trim() !== "production") {
basePath = "/lst";
}
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Db connection stuff
// express app
const app = express();
// global middleware
app.use(express.static(path.join(__dirname, "../lstDocs/build")));
app.use(express.static(path.join(__dirname, "../frontend/dist")));
// global env that run only in dev
if (process.env.NODE_ENV?.trim() !== "production") {
app.use(morgan("tiny"));
}
// docs and api stuff
app.use(
basePath + "/d",
express.static(join(__dirname, "../lstDocs/build"))
);
app.use(
basePath + "/app",
express.static(join(__dirname, "../frontend/dist"))
);
// register app
setupRoutes(app, basePath);
// ws stuff
// ws + server stuff
const server = createServer(app);
// sub systems
printers();
// start the server up
server.listen(PORT, "0.0.0.0", () =>
console.log(
`Server running in ${process.env.NODE_ENV}, on http://0.0.0.0:${PORT}${basePath}`
)
);
};
main().catch((err) => {
console.error("Startup error:", err);
process.exit(1);
});