2023-02-09 20:34:53 +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.
|
|
|
|
|
2023-02-16 10:39:19 +00:00
|
|
|
console.log(`Initialising OwlBoard`)
|
|
|
|
|
2023-02-09 20:34:53 +00:00
|
|
|
// External Requires
|
|
|
|
const express = require('express');
|
|
|
|
const app = express();
|
|
|
|
const compression = require('compression')
|
|
|
|
|
|
|
|
// Internal Requires
|
|
|
|
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 findRtr = require('./src/routes/find.routes'); // /find endpoints
|
|
|
|
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
|
|
|
|
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
|
|
|
|
|
|
|
|
// Set Server Configurations
|
|
|
|
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
|
|
|
|
const srvPort = process.env.OWL_SRV_PORT || 8460
|
|
|
|
|
|
|
|
// Print version number:
|
2023-03-30 21:10:39 +01:00
|
|
|
log.out(`app: Starting OwlBoard - Backend Version: ${version.app} - API versions: ${version.api}`, "init");
|
2023-02-09 20:34:53 +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
|
|
|
|
|
|
|
|
// Express Error Handling:
|
|
|
|
app.use((err, req, res, next) => {
|
|
|
|
const statusCode = err.statuscode || 500;
|
|
|
|
console.error(err.message, err.stack);
|
|
|
|
res.status(statusCode).json({'message': err.message});
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Express Submodules:
|
|
|
|
app.use(express.json()); //JSON Parsing for POST Requests
|
2023-02-16 21:25:19 +00:00
|
|
|
//STATIC CONTENT NO LONGER SERVED FROM NODE
|
|
|
|
app.use(compression()) // Compress API Data if supported by client
|
2023-02-09 20:34:53 +00:00
|
|
|
|
|
|
|
// Express Routes
|
|
|
|
app.use('/api/v1/list', listRtr);
|
|
|
|
app.use('/api/v1/ldb', ldbRtr);
|
|
|
|
app.use('/api/v1/kube', kubeRtr);
|
|
|
|
app.use('/api/v1/find', findRtr);
|
|
|
|
app.use('/api/v1/issue', issueRtr);
|
|
|
|
app.use('/api/v1/stats', statRtr)
|
|
|
|
|
|
|
|
// Start Express
|
|
|
|
app.listen(srvPort, srvListen, (error) =>{
|
|
|
|
if(!error) {
|
2023-03-30 21:10:39 +01:00
|
|
|
log.out(`app.listen: Listening on http://${srvListen}:${srvPort}`, "init");
|
|
|
|
log.out("app.listen: State - alive", "init")
|
2023-02-09 20:34:53 +00:00
|
|
|
} else {
|
2023-03-30 21:10:39 +01:00
|
|
|
log.out(`app.listen: Error occurred, server can't start ${error}`, "err");
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
});
|