Shell for UI pages, some placeholder dashboard stats
This commit is contained in:
25
src/backend/internal/report.js
Normal file
25
src/backend/internal/report.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const error = require('../lib/error');
|
||||
|
||||
const internalReport = {
|
||||
|
||||
/**
|
||||
* @param {Access} access
|
||||
* @return {Promise}
|
||||
*/
|
||||
getHostsReport: access => {
|
||||
return access.can('reports:hosts', 1)
|
||||
.then(() => {
|
||||
return {
|
||||
proxy: 12,
|
||||
redirection: 2,
|
||||
stream: 1,
|
||||
'404': 0
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = internalReport;
|
7
src/backend/lib/access/reports-hosts.json
Normal file
7
src/backend/lib/access/reports-hosts.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "roles#/definitions/user"
|
||||
}
|
||||
]
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
const express = require('express');
|
||||
const pjson = require('../../../../package.json');
|
||||
const error = require('../../lib/error');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -28,5 +29,16 @@ router.get('/', (req, res/*, next*/) => {
|
||||
|
||||
router.use('/tokens', require('./tokens'));
|
||||
router.use('/users', require('./users'));
|
||||
router.use('/reports', require('./reports'));
|
||||
|
||||
/**
|
||||
* API 404 for all other routes
|
||||
*
|
||||
* ALL /api/*
|
||||
*/
|
||||
router.all(/(.+)/, function (req, res, next) {
|
||||
req.params.page = req.params['0'];
|
||||
next(new error.ItemNotFoundError(req.params.page));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
31
src/backend/routes/api/reports.js
Normal file
31
src/backend/routes/api/reports.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const internalReport = require('../../internal/report');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
});
|
||||
|
||||
router
|
||||
.route('/hosts')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /reports/hosts
|
||||
*/
|
||||
.get(jwtdecode(), (req, res, next) => {
|
||||
internalReport.getHostsReport(res.locals.access)
|
||||
.then(data => {
|
||||
res.status(200)
|
||||
.send(data);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
Reference in New Issue
Block a user