added routes for hosts
This commit is contained in:
parent
7a05f6826f
commit
9bf224a8cb
@ -20,6 +20,22 @@ async function listAll(){
|
||||
}
|
||||
|
||||
|
||||
async function listAllDetail(){
|
||||
try{
|
||||
let out = [];
|
||||
let hosts = await listAll();
|
||||
|
||||
for(let host of hosts){
|
||||
out.push(await getInfo({host}));
|
||||
}
|
||||
|
||||
return out
|
||||
}catch(error){
|
||||
return new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function add(data){
|
||||
|
||||
try{
|
||||
@ -53,4 +69,4 @@ async function remove(data){
|
||||
}
|
||||
|
||||
|
||||
module.exports = {getInfo, listAll, add, remove};
|
||||
module.exports = {getInfo, listAll, listAllDetail, add, remove};
|
||||
|
@ -17,8 +17,9 @@ router.get('/:host', async function(req, res){
|
||||
|
||||
router.get('/', async function(req, res){
|
||||
try{
|
||||
let hosts = await Host.listAll();
|
||||
return res.json({hosts: hosts});
|
||||
return res.json({
|
||||
hosts: req.query.detail ? await host.listAllDetail() : await Host.listAll()
|
||||
});
|
||||
}catch(error){
|
||||
return res.status(500).json({message: `ERROR ${error}`});
|
||||
}
|
||||
@ -36,10 +37,11 @@ router.post('/', async function(req, res){
|
||||
}
|
||||
|
||||
try{
|
||||
await Host.add({host, ip, targetPort,
|
||||
username: req.user.username,
|
||||
forceSSL: req.body.forceSSL,
|
||||
targetSSL: req.body.targetSSL,
|
||||
await Host.add({
|
||||
host, ip, targetPort,
|
||||
username: req.user.username,
|
||||
forceSSL: req.body.forceSSL,
|
||||
targetSSL: req.body.targetSSL,
|
||||
});
|
||||
|
||||
return res.json({
|
||||
@ -54,28 +56,21 @@ router.post('/', async function(req, res){
|
||||
|
||||
});
|
||||
|
||||
router.delete('/', async function(req, res){
|
||||
let host = req.body.host;
|
||||
let count;
|
||||
|
||||
if(!host){
|
||||
return res.status(400).json({
|
||||
message: `Missing fields: ${!host ? 'host' : ''}`
|
||||
});
|
||||
}
|
||||
router.delete('/:host', async function(req, res, next){
|
||||
let host = req.params.host;
|
||||
|
||||
try{
|
||||
count = await Host.remove({host});
|
||||
let count = await Host.remove({host});
|
||||
|
||||
return res.json({
|
||||
message: `Host ${host} deleted`,
|
||||
});
|
||||
|
||||
}catch(error){
|
||||
return res.status(500).json({
|
||||
message: `ERROR: ${error}`
|
||||
});
|
||||
}
|
||||
|
||||
return res.json({
|
||||
message: `Host ${host} deleted`,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -2,8 +2,23 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function(req, res, next) {
|
||||
res.render('index', { title: 'Express' });
|
||||
router.get('/', async function(req, res, next) {
|
||||
res.render('hosts', { title: 'Express' });
|
||||
});
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/hosts', function(req, res, next) {
|
||||
res.render('hosts', { title: 'Express' });
|
||||
});
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/users', function(req, res, next) {
|
||||
res.render('users', { title: 'Express' });
|
||||
});
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/login', function(req, res, next) {
|
||||
res.render('login', {redirect: req.query.redirect});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
Loading…
x
Reference in New Issue
Block a user