mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Add API endpoints for loading devices.
This commit is contained in:
parent
52ae7765c8
commit
c119e2c3d2
2 changed files with 38 additions and 0 deletions
|
@ -92,6 +92,36 @@ module.exports = function(options) {
|
|||
res.render('index')
|
||||
})
|
||||
|
||||
app.get('/api/v1/devices', function(req, res) {
|
||||
dbapi.loadDevices()
|
||||
.then(function(cursor) {
|
||||
return Promise.promisify(cursor.toArray, cursor)()
|
||||
.then(function(list) {
|
||||
res.json(list)
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Failed to load device list: ', err.stack)
|
||||
res.send(500)
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/api/v1/devices/:serial', function(req, res) {
|
||||
dbapi.loadDevice(req.params.serial)
|
||||
.then(function(device) {
|
||||
if (device) {
|
||||
res.json(device)
|
||||
}
|
||||
else {
|
||||
res.send(404)
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Failed to load device "%s": ', req.params.serial, err.stack)
|
||||
res.send(500)
|
||||
})
|
||||
})
|
||||
|
||||
io.set('authorization', (function() {
|
||||
var parse = Promise.promisify(express.cookieParser(options.secret))
|
||||
return function(handshake, accept) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue