Initial commit

This commit is contained in:
2026-06-29 20:14:06 +02:00
commit e0488f8081
21 changed files with 1840 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
/*
! /servers/Dashboard/functions.js Central Dashboard Server Functions
? This modules exports the functionality for the express dashboard server
*/
// % core variables
const ip = process.env.INTERNAL_HOST_IP;
const port = process.env.INTERNAL_DASHBOARD_PORT;
// $ server start function
async function boot(server) {
// ~ start express server
server.listen(port, ip, () => {
console.info(`Express server is now running on http://${ip}:${port}`)
});
// ~ return running express server reference
return server;
};
// $ server shutdown function
async function shutdown(server) {
// ~ shutdown running express server
server.close();
// ~ return express server reference
return server;
};
// $ server restart function
async function restart(server) {
// ~ shutdown the running express server
await shutdown(server);
// ~ restart the express server
await boot(server);
// ~ return the server reference
return server;
};
// $ server status function
async function status(server) {
// ~ get and return server listening status
return server.listening ? 'online' : 'offline';
};
// § export server functions module
module.exports = { boot, shutdown, restart, status };
+32
View File
@@ -0,0 +1,32 @@
/*
! /servers/dashboard/routers/index.js Central Gateway Routing Aggregator
? This module dynamically collects and registeres all modular ".router.js" files within the "routers" directory
*/
// % import nodejs packages
const router = require('express').Router();
const path = require('path');
const fs = require('fs');
// % import external dependencies
const rootDir = path.resolve(__dirname, '..', '..', '..');
const { dirs } = require(path.resolve(rootDir, 'configuration', 'mapping.js'));
// % read router files recursively
const routerRoot = path.resolve(dirs.dashboardDir, 'routers');
const routerFiles = fs.readdirSync(routerRoot)
.filter(file => /\.router\.js$/.test(file))
.sort((a, b) => {
if (a === 'root.router.js') return 1;
if (b === 'root.router.js') return -1;
return a.localeCompare(b);
});
// $ configure used routers
routerFiles.forEach(file => {
const routerPath = path.resolve(routerRoot, file);
router.use(require(routerPath));
});
// § export router module
module.exports = router;
+35
View File
@@ -0,0 +1,35 @@
/*
! /servers/dashboard/server.js Central Dashboard Server Manager
? This module orchestrates the express lifecycle, handles initialization, middleware configs and router integrations.
*/
// % import nodejs packages
const express = require('express');
const http = require('http');
const path = require('path');
// % import external dependencies
const rootDir = path.resolve(__dirname, '..', '..');
const { dirs } = require(path.resolve(rootDir, 'configuration', 'mapping.js'));
// % set up express server
const app = express();
const server = http.createServer(app);
// $ server setup
app.use(express.json()); // add json support for express
app.use(express.static(path.resolve(dirs.interfaceDir, 'resources'))); // set resources directory (e.g. scripts, style sheets, images ...)
app.set('view engine', 'ejs'); // set "embedded javascript" as view engine
app.set('views', path.resolve(dirs.interfaceDir, 'views')); // set the folder where the .ejs files are located
// $ router setup
const router = require(path.resolve(dirs.dashboardDir, 'routers'));
app.use(router);
// $ server functions
const {
boot, shutdown, restart, status
} = require(path.resolve(dirs.dashboardDir, 'functions.js'));
// $ export server module
module.exports = { boot, shutdown, restart, status, server };