Where we are now
This commit is contained in:
parent
7b986a04a5
commit
4116b7a339
92
app.js
Normal file
92
app.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// OwlBoard - © Fred Boniface 2022
|
||||||
|
// Licensed under GPLv3 (or later)
|
||||||
|
// Please see the included LICENSE file
|
||||||
|
|
||||||
|
// Version Number:
|
||||||
|
var version = "0.0.1"
|
||||||
|
console.log(`Starting OwlBoard version ${version}`)
|
||||||
|
|
||||||
|
// Load Modules:
|
||||||
|
const fs = require('fs');
|
||||||
|
const ldb = require('ldbs-json');
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
// Get API Keys:
|
||||||
|
try {
|
||||||
|
var keys = JSON.parse(fs.readFileSync('/srv/keys/owlboard/keys.json', 'utf8'));
|
||||||
|
console.log('API Keys loaded from /srv/keys/ownboard/keys.json');
|
||||||
|
} catch (err) {
|
||||||
|
var keys = 'ERR';
|
||||||
|
console.error('Unable to obtain API Keys from file');
|
||||||
|
console.error(err);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get Settings:
|
||||||
|
try {
|
||||||
|
var settings = JSON.parse(fs.readFileSync('./settings.json', 'utf8'));
|
||||||
|
console.log("Settings loaded from .settings.json");
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Unable to load settings, using defaults', err);
|
||||||
|
var settings = {"webPort":8460,"listen":"localhost"};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create Web Service:
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.listen(settings.webPort, (error) =>{
|
||||||
|
if(!error)
|
||||||
|
console.log(`Server is running on http://${settings.listen}:${settings.webPort}`)
|
||||||
|
else
|
||||||
|
console.log("Error occurred, server can't start", error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Check Athena API Key:
|
||||||
|
|
||||||
|
// Routes:
|
||||||
|
|
||||||
|
app.get('/', (req, res)=>{
|
||||||
|
res.status(200);
|
||||||
|
res.set('Content-Type', 'application/json');
|
||||||
|
res.send(JSON.stringify({"OwlBoard_Status":"ready","OwlBoard_Version":version}));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/test', (req, res)=>{
|
||||||
|
const {test} = req.body;
|
||||||
|
res.status(200);
|
||||||
|
res.set('Content-Type', 'application/json');
|
||||||
|
res.send(JSON.stringify({"test_outcome":"success","post_value":test}))
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post('/arrdep', (req, res)=>{
|
||||||
|
//Check Validity and Auth then return ArrDep JSON
|
||||||
|
const {reqCode} = req.body;
|
||||||
|
const {auth} = req.body;
|
||||||
|
const permit = checkAuth(auth);
|
||||||
|
const valid = checkValid(reqCode);
|
||||||
|
res.set('Content-Type', 'application/json');
|
||||||
|
if (permit == false) { //This should be the other way round - If Valid&Auth then return, elif not auth, elif invalid elif UnknownError
|
||||||
|
res.status(401);
|
||||||
|
res.send(JSON.stringify({"status":"fail","error":"Not Authorised"}));
|
||||||
|
} else if (valid == false) {
|
||||||
|
res.status(404);
|
||||||
|
res.send(JSON.stringify({"status":"fail","error":"Location not Recognized"}));
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post('/stations', (req, res)=>{
|
||||||
|
//Return JSON of all available stations - No Auth Required
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// General Functions
|
||||||
|
function checkValid(input){
|
||||||
|
// Check validity of the entered CRS/Tiploc against DB
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAuth(downstreamKey){
|
||||||
|
// Check the downstream requester has authority to get depBoards
|
||||||
|
}
|
32
express.js
32
express.js
@ -1,32 +0,0 @@
|
|||||||
// OwlBoard - © Fred Boniface 2022
|
|
||||||
// Licensed under GPLv3 (or later)
|
|
||||||
// Please see the included LICENSE file
|
|
||||||
|
|
||||||
// Load Modules
|
|
||||||
const fs = require('fs');
|
|
||||||
const ldb = require('ldbs-json');
|
|
||||||
const bodyParser = require('body-parser');
|
|
||||||
const exit = require('process');
|
|
||||||
const express = require('express');
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
// Get API Keys:
|
|
||||||
// - Keys are available as keys.ldbws and keys.ldbsvws
|
|
||||||
try {
|
|
||||||
const keys = JSON.parse(fs.readFileSync('/srv/keys/owlboard/keys.json', 'utf8'));
|
|
||||||
console.log('API Keys loaded from file');
|
|
||||||
} catch (err) {
|
|
||||||
const keys = 'ERR';
|
|
||||||
console.error('Unable to obtain API Keys from file');
|
|
||||||
console.error(err);
|
|
||||||
exit
|
|
||||||
};
|
|
||||||
|
|
||||||
// Define Web Service:
|
|
||||||
var server = app.listen(8080, function () {
|
|
||||||
var host = server.address().address
|
|
||||||
var port = server.address().port
|
|
||||||
console.log("Example app listening at http://%s:%s", host, port)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Define Output Functions:
|
|
16
package.json
16
package.json
@ -2,5 +2,19 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"ldbs-json": "^1.2.1"
|
"ldbs-json": "^1.2.1"
|
||||||
}
|
},
|
||||||
|
"name": "owlboard",
|
||||||
|
"description": "OwlBoard is the backend API that powers the Athena web application at athena.fb-infra.uk.",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"main": "express.js",
|
||||||
|
"devDependencies": {},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.fjla.uk/fred.boniface/owlboard.git"
|
||||||
|
},
|
||||||
|
"author": "Fred Boniface",
|
||||||
|
"license": "GPL-3.0-or-later"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user