Testing Phases

This commit is contained in:
Fred Boniface 2022-11-29 22:30:45 +00:00
parent 7c29eceabd
commit 7b986a04a5
6 changed files with 1261 additions and 1 deletions

View File

@ -1,3 +1,11 @@
# OwlBoard
Backend API used in Athena.
OwlBoard is the backend API that powers the Athena web application at athena.fb-infra.uk.
Powered by Node.JS and using the ldbs-json module, the OwlBoard API provides up to date train departure information for any station in the UK.
Whilst the application is open source, the webservice (owlboard.fb-infra.uk) is not openly available. National Rail Enquiries have limits on API access so to use this software yourself, you'll need to run your own instance after obtaining your own API key.
## Default Settings
webPort: 8460

32
express.js Normal file
View File

@ -0,0 +1,32 @@
// 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:

68
http.js Normal file
View File

@ -0,0 +1,68 @@
// OwlBoard - © Fred Boniface 2022
// Licensed under GPLv3 (or later)
// Please see the included LICENSE file
// Version Number:
var version = 0.1
console.log(`Starting OwlBoard version ${version}`)
// Load Modules:
const fs = require('fs');
const ldb = require('ldbs-json');
const http = require('http');
const url = require('url');
// 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:
//let 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');
console.log(err);
var settings = {"webPort":8460,"listen":"localhost"};
};
// Create Web Service:
try {
http.createServer((req, res) => {
const queryOpt = url.parse(req.url, true).query;
const query = url.parse(req.url, true).pathname.replace(/[/]/g, '');
switch (req.url){
case "":
res.writeHead(200, { 'Content-Type':'application/json' });
res.end(JSON.stringify({"OwlBoardStatus":"ready","OwnBoardVersion":version}));
break;
}
switch (req.url){
case "/crs":
res.writeHead(200, { 'Content-Type':'application/json'});
res.end(crs);
break;
}
}).listen(settings.webPort);
console.log(`Web server started on http://${settings.listen}:${settings.webPort}`);
} catch (err) {
console.error('Unable to start webserver');
console.error(err);
};
// Check Athena API Key:
// Routes:
var crs = JSON.stringify({"resource":"crs_lookup"});

1145
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"express": "^4.18.2",
"ldbs-json": "^1.2.1"
}
}

1
settings.json Normal file
View File

@ -0,0 +1 @@
{"webPort":8460,"listen":"localhost"}