wild card socket lookup

This commit is contained in:
2020-12-21 21:28:59 -05:00
parent ea319109a2
commit 9c3d29bb7b
3 changed files with 224 additions and 66 deletions
+41 -30
View File
@@ -4,38 +4,11 @@ const router = require('express').Router();
const {Host} = require('../models/host');
router.get('/:host', async function(req, res, next){
try{
return res.json({
host: req.params.host,
results: await Host.get({host: req.params.host})
});
}catch(error){
return next(error);
}
});
router.get('/', async function(req, res, next){
try{
return res.json({
hosts: await Host[req.query.detail ? "listDetail" : "list"]()
});
}catch(error){
next(error)
}
});
router.put('/:host', async function(req, res, next){
try{
req.body.updated_by = req.user.username;
let host = await Host.get(req.params.host);
await host.update(req.body);
return res.json({
message: `Host "${req.params.host}" updated.`
});
}catch(error){
return next(error);
}
@@ -50,13 +23,39 @@ router.post('/', async function(req, res, next){
message: `Host "${req.body.host}" added.`
});
} catch (error){
next(error);
return next(error);
}
});
router.get('/:host', async function(req, res, next){
try{
return res.json({
host: req.params.host,
results: await Host.get({host: req.params.host})
});
}catch(error){
return next(error);
}
});
router.put('/:host', async function(req, res, next){
try{
req.body.updated_by = req.user.username;
let host = await Host.get(req.params.host);
await host.update(req.body);
return res.json({
message: `Host "${req.params.host}" updated.`
});
}catch(error){
return next(error);
}
});
router.delete('/:host', async function(req, res, next){
try{
let host = await Host.get(req.params);
let count = await host.remove(host);
@@ -66,7 +65,19 @@ router.delete('/:host', async function(req, res, next){
});
}catch(error){
next(error);
return next(error);
}
});
router.get('/lookup/:host', async function(req, res, next){
try{
return res.json({
string: req.params.host,
results: await Host.lookUp(req.params.host),
});
}catch(error){
return next(error);
}
});
+19 -3
View File
@@ -1,19 +1,23 @@
'use strict';
var express = require('express');
var router = express.Router();
const {Host} = require('../models/host');
/* GET home page. */
router.get('/', async function(req, res, next) {
res.render('hosts', { title: 'Express' });
res.render('hosts', {});
});
/* GET home page. */
router.get('/hosts', function(req, res, next) {
res.render('hosts', { title: 'Express' });
res.render('hosts', {});
});
/* GET home page. */
router.get('/users', function(req, res, next) {
res.render('users', { title: 'Express' });
res.render('users', {});
});
/* GET home page. */
@@ -21,4 +25,16 @@ router.get('/login', function(req, res, next) {
res.render('login', {redirect: req.query.redirect});
});
router.get('/lookup/:host', async function(req, res, next){
try{
return res.json({
string: req.params.host,
results: await Host.lookUp(req.params.host),
});
}catch(error){
return next(error);
}
});
module.exports = router;