Extend store API

This commit is contained in:
Zalmoxisus
2016-11-12 16:16:43 +02:00
parent 6794f63629
commit 1ba4d1e40b
4 changed files with 20 additions and 10 deletions

View File

@ -17,15 +17,15 @@ module.exports.run = function(worker) {
app.set('view engine', 'ejs');
app.set('views', path.resolve(__dirname, '..', 'views'));
app.get('*', function(req, res) {
res.render('index', { port: worker.options.port });
});
if (logHTTPRequests) {
if (typeof logHTTPRequests === 'object') app.use(morgan('combined', logHTTPRequests));
else app.use(morgan('combined'));
}
app.get('*', function(req, res) {
res.render('index', { port: worker.options.port });
});
app.use(cors({ methods: 'POST' }));
app.use(bodyParser.json({ limit: limit }));
app.use(bodyParser.urlencoded({ limit: limit, extended: false }));
@ -34,7 +34,7 @@ module.exports.run = function(worker) {
switch(req.body.op) {
case 'get':
store.get(req.body.id).then(function(r) {
res.send(r[0] || {});
res.send(r || {});
}).catch(function(error) {
console.error(error);
res.sendStatus(500)
@ -98,7 +98,7 @@ module.exports.run = function(worker) {
});
socket.on('getReport', function (id, respond) {
store.get(id).then(function(data) {
respond(null, data[0]);
respond(null, data);
}).catch(function(error) {
console.error(error);
});