FullStack: Move stats endpoint

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-02-02 19:49:44 +00:00
parent c4ad5a32f0
commit 9450fc6fe2
7 changed files with 41 additions and 13 deletions

2
app.js
View File

@ -20,6 +20,7 @@ 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
const initDb = require('./src/utils/dbinit.utils'); // DB Init Utility
// Set Server Configurations
@ -59,6 +60,7 @@ 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) =>{

View File

@ -0,0 +1,13 @@
const stat = require('../services/stats.services');
async function get(req, res, next) {
try {
res.json(await stat.hits())
} catch (err) {
console.error(`Controller Error`, err);
next(err);
}
}
module.exports = {
get}

View File

@ -16,6 +16,5 @@ const listController = require('../controllers/list.controllers');
router.get('/stations', listController.getStations);
router.get('/corpus', listController.getCorpus);
router.get('/hits', listController.hits)
module.exports = router;

View File

@ -0,0 +1,8 @@
const express = require('express');
const router = express.Router();
const statsController = require('../controllers/stats.controllers');
router.get('/', statsController.get);
module.exports = router;

View File

@ -14,17 +14,7 @@ async function getCorpus(){
return out;
}
async function hits(){
var dat = await db.query("meta", {target: "counters"});
log.out(`listServices.meta: fetched server meta`)
let out = {}
out.host = os.hostname()
out.dat = dat
return out;
}
module.exports = {
getStations,
getCorpus,
hits
getCorpus
}

View File

@ -0,0 +1,16 @@
const log = require('../utils/log.utils'); // Log Helper
const db = require('../services/dbAccess.services')
const os = require('os')
async function hits(){
var dat = await db.query("meta", {target: "counters"});
log.out(`listServices.meta: fetched server meta`)
let out = {}
out.host = os.hostname()
out.dat = dat
return out;
}
module.exports = {
hits
}

View File

@ -5,7 +5,7 @@ async function init() {
}
async function get() {
var url = `${window.location.origin}/api/v1/list/hits`;
var url = `${window.location.origin}/api/v1/stats`;
var resp = await fetch(url);
return await resp.json();
}