Improve logging
This commit is contained in:
parent
51023fbd64
commit
a00a8002bb
|
@ -22,6 +22,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.15.2",
|
"body-parser": "^1.15.2",
|
||||||
"freezer-js": "^0.6.0",
|
"freezer-js": "^0.6.0",
|
||||||
|
"moment": "^2.17.1",
|
||||||
"qrcode.react": "^0.6.1",
|
"qrcode.react": "^0.6.1",
|
||||||
"react": "^0.13.0",
|
"react": "^0.13.0",
|
||||||
"react-router": "^0.13.3",
|
"react-router": "^0.13.3",
|
||||||
|
|
18
server.js
18
server.js
|
@ -1,6 +1,7 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
@ -9,6 +10,10 @@ const port = 3000;
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
|
|
||||||
|
function log(message) {
|
||||||
|
console.log(moment().format() + ': ' + message);
|
||||||
|
}
|
||||||
|
|
||||||
app.use('/', express.static(path.join(__dirname, 'public')));
|
app.use('/', express.static(path.join(__dirname, 'public')));
|
||||||
app.get('/*', (req, res) => {
|
app.get('/*', (req, res) => {
|
||||||
res.sendFile(path.join(__dirname, 'public/index.html'));
|
res.sendFile(path.join(__dirname, 'public/index.html'));
|
||||||
|
@ -21,18 +26,20 @@ app.post('*', (req, res) => {
|
||||||
if (data && data.substring(0,2) === 'd:') {
|
if (data && data.substring(0,2) === 'd:') {
|
||||||
let message = data.substring(2);
|
let message = data.substring(2);
|
||||||
|
|
||||||
console.log("to: " + id);
|
log('[NOTICA] Message sent to ' + id + ': ' + message);
|
||||||
console.log(message);
|
|
||||||
|
|
||||||
io.in(id).emit('message', message);
|
io.in(id).emit('message', message);
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
|
} else {
|
||||||
|
log('Ignoring bad POST data to: ' + id);
|
||||||
|
res.send('Bad POST data.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = app.listen(port, 'localhost', (err) => {
|
const server = app.listen(port, 'localhost', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
log('[ERROR] Server error: ' + err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.info('==> Listening on port %s. Open up %s:%s/ in your browser.', port, host, port);
|
console.info('==> Listening on port %s. Open up %s:%s/ in your browser.', port, host, port);
|
||||||
|
@ -41,11 +48,8 @@ const server = app.listen(port, 'localhost', (err) => {
|
||||||
const io = require('socket.io').listen(server);
|
const io = require('socket.io').listen(server);
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log("new connection!");
|
|
||||||
socket.on('room', (room) => {
|
socket.on('room', (room) => {
|
||||||
console.log("telling it to join room.");
|
log('New connection joining room: ' + room);
|
||||||
socket.join(room);
|
socket.join(room);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user