intials app
This commit is contained in:
1
app/src/internal/ocp/printers/printers.ts
Normal file
1
app/src/internal/ocp/printers/printers.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const printers = () => {};
|
||||
15
app/src/internal/routerHandler/routeHandler.ts
Normal file
15
app/src/internal/routerHandler/routeHandler.ts
Normal 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" });
|
||||
});
|
||||
}
|
||||
10
app/src/internal/routerHandler/routes/healthRoutes.ts
Normal file
10
app/src/internal/routerHandler/routes/healthRoutes.ts
Normal 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
67
app/src/main.ts
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user