Persist reports in memory

This commit is contained in:
Zalmoxisus
2016-08-17 17:56:42 +03:00
parent 0fb42d9f75
commit e53679087b
6 changed files with 45 additions and 4 deletions

View File

@ -2,10 +2,12 @@ var path = require('path');
var app = require('express')();
var bodyParser = require('body-parser');
var cors = require('cors');
var createStore = require('./store');
module.exports.run = function(worker) {
var httpServer = worker.httpServer;
var scServer = worker.scServer;
var store;
httpServer.on('request', app);
@ -20,8 +22,11 @@ module.exports.run = function(worker) {
app.use(bodyParser.json());
app.post('/', function(req, res) {
if (!req.body) return res.status(404).end();
scServer.exchange.publish('log', req.body);
res.send('OK');
if (!store) store = createStore(worker.options);
store.add(req.body).then(function(r) {
scServer.exchange.publish('log', req.body);
res.send({ id: r.id });
});
});
scServer.addMiddleware(scServer.MIDDLEWARE_EMIT, function (req, next) {