wild card socket lookup
This commit is contained in:
+41
-30
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user