Support passing data sent via post request

This commit is contained in:
Zalmoxisus 2016-05-02 13:49:06 +03:00
parent 6cc421a84e
commit 8672c8e95b
2 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,7 @@
var path = require('path');
var app = require('express')();
var bodyParser = require('body-parser');
var cors = require('cors');
module.exports.run = function(worker) {
var httpServer = worker.httpServer;
@ -13,9 +15,12 @@ module.exports.run = function(worker) {
app.get('/', function(req, res) {
res.render('index', { port: worker.options.port });
});
app.use(cors({ methods: 'POST' }));
app.use(bodyParser.json());
app.post('/', function(req, res) {
if (!req.body.data) return res.status(404).end();
scServer.exchange.publish('log', req.body.data);
if (!req.body) return res.status(404).end();
scServer.exchange.publish('log', req.body);
res.send('OK');
});

View File

@ -25,6 +25,8 @@
},
"homepage": "https://github.com/zalmoxisus/remotedev-server",
"dependencies": {
"body-parser": "^1.15.0",
"cors": "^2.7.1",
"ejs": "^2.4.1",
"express": "^4.13.3",
"minimist": "^1.2.0",