Add checking to make sure received message is valid

This commit is contained in:
Tanner Collin 2016-12-24 15:27:38 -07:00
parent fd95bd10b7
commit 71598b8d76

View File

@ -17,14 +17,18 @@ app.get('/*', (req, res) => {
app.post('*', (req, res) => { app.post('*', (req, res) => {
let id = req.path.substring(1); let id = req.path.substring(1);
let message = Object.keys(req.body)[0]; let data = Object.keys(req.body)[0];
console.log("to: " + id); if (data && data.substring(0,2) === 'd:') {
console.log(message); let message = data.substring(2);
io.in(id).emit('message', message); console.log("to: " + id);
console.log(message);
res.end(); io.in(id).emit('message', message);
res.end();
}
}); });
const server = app.listen(port, 'localhost', (err) => { const server = app.listen(port, 'localhost', (err) => {