This repository has been archived on 2023-08-24. You can view files and clone it, but cannot push or open issues or pull requests.
OwlBoard/app.js

63 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-11-30 22:08:27 +00:00
// OwlBoard - © Fred Boniface 2022 - Licensed under GPLv3 (or later)
// Please see the included LICENSE file. Statically served fonts are
// licensed separately, each folder contains a license file where a
// different license applies.
2022-11-30 00:21:59 +00:00
2022-12-22 07:56:56 +00:00
// External Requires
2022-11-30 14:32:36 +00:00
const express = require('express');
const app = express();
2022-12-22 07:56:56 +00:00
// Internal Requires
2023-01-05 21:00:39 +00:00
const log = require('./src/utils/log.utils'); // Log Helper
const version = require('./src/configs/version.configs'); // Version Strings
const listRtr = require('./src/routes/list.routes'); // /list endpoints
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
const initDb = require('./src/utils/dbinit.utils') // DB Init Utility
2022-11-30 00:21:59 +00:00
// Set Server Configurations
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
const srvPort = process.env.OWL_SRV_PORT || 8460
2022-12-01 13:40:24 +00:00
// Print version number:
log.out(`app: Starting OwlBoard - App Version: ${version.app} - API versions: ${version.api}`);
2022-11-30 00:21:59 +00:00
2022-12-24 10:40:13 +00:00
// Test for required vars:
// const varTest = require('./src/utils/varTest.utils');
// var startTest = await varTest.varTest();
//console.log("Required Vars Missing:", startTest.missing_required);
//console.log("Desired Vars Missing:", startTest.missing_desired);
// if startTest.pass == false
// console.log("Unable to start, missing required vars")
// exit app
2023-01-05 21:00:39 +00:00
// DB Init
2023-01-10 20:54:19 +00:00
initDb.init();
2023-01-05 21:00:39 +00:00
// Express Error Handling:
2022-12-01 13:40:24 +00:00
app.use((err, req, res, next) => {
const statusCode = err.statuscode || 500;
console.error(err.message, err.stack);
res.status(statusCode).json({'message': err.message});
2022-12-01 13:53:32 +00:00
return;
2022-11-30 00:21:59 +00:00
});
// Express Submodules:
2022-12-01 22:07:20 +00:00
app.use(express.json()); //JSON Parsing for POST Requests
2022-12-19 18:38:57 +00:00
app.use(express.static('static')); //Serve static content from /static
2022-12-01 22:07:20 +00:00
// Express Routes
2022-12-01 22:07:20 +00:00
app.use('/api/v1/list', listRtr);
app.use('/api/v1/ldb', ldbRtr);
app.use('/api/v1/kube', kubeRtr);
2022-11-30 00:21:59 +00:00
// Start Express
app.listen(srvPort, srvListen, (error) =>{
2022-12-01 13:40:24 +00:00
if(!error) {
log.out(`app.listen: Listening on http://${srvListen}:${srvPort}`);
log.out("app.listen: State - alive")
2022-12-01 13:40:24 +00:00
} else {
log.out("app.listen: Error occurred, server can't start", error);
2022-12-01 13:40:24 +00:00
}
});