arma-server-web-admin/routes/logs.js

34 lines
712 B
JavaScript
Raw Normal View History

var express = require('express')
2017-04-01 09:19:30 +00:00
module.exports = function (logsManager) {
var router = express.Router()
2017-04-01 09:19:30 +00:00
router.get('/', function (req, res) {
logsManager.logFiles(function (err, files) {
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
res.json(files)
}
})
})
router.get('/:log', function (req, res) {
var requestedFilename = req.params.log
2017-04-01 09:19:30 +00:00
logsManager.getLogFile(requestedFilename, function (err, file) {
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
if (file) {
res.download(file.path)
} else {
res.status(404).send(new Error('File not found'))
}
2017-04-01 09:19:30 +00:00
}
})
})
2017-04-01 09:19:30 +00:00
return router
}