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

34 lines
725 B
JavaScript
Raw Normal View History

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