2016-01-22 08:22:11 -06:00
|
|
|
/* jshint -W079 */
|
2016-04-09 05:09:53 -05:00
|
|
|
(function () {
|
|
|
|
var Scribe = require('../');
|
|
|
|
var express = require('express');
|
|
|
|
var path = require('path');
|
2016-04-11 06:16:51 -05:00
|
|
|
var http = require('http');
|
2016-04-09 05:09:53 -05:00
|
|
|
var bodyParser = require('body-parser');
|
|
|
|
var app = express();
|
2016-04-11 06:16:51 -05:00
|
|
|
var server = http.createServer(app);
|
|
|
|
var port = process.env.PORT || 5000;
|
2016-04-09 05:09:53 -05:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
"app": 'simple-server',
|
|
|
|
"id": process.pid,
|
|
|
|
"module": {
|
|
|
|
"writer/MongoDB": {
|
|
|
|
"uri": process.env.MONGOLAB_URI || "mongodb://localhost/scribe"
|
|
|
|
},
|
|
|
|
"router/Viewer": {
|
2016-04-11 06:16:51 -05:00
|
|
|
"mongoUri": process.env.MONGOLAB_URI || "mongodb://localhost/scribe",
|
|
|
|
"username": false,
|
|
|
|
"password": false
|
2016-04-09 05:09:53 -05:00
|
|
|
},
|
|
|
|
"writer/SocketIO": {
|
2016-04-11 06:16:51 -05:00
|
|
|
"server": server,
|
2016-04-09 05:09:53 -05:00
|
|
|
"options": {}
|
|
|
|
},
|
|
|
|
"router/Viewer/client": {
|
|
|
|
"background": "#222",
|
|
|
|
"socketPorts": [
|
2016-04-11 06:16:51 -05:00
|
|
|
process.env.PORT ? 443 : port
|
2016-04-09 05:09:53 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"debug": false
|
|
|
|
};
|
|
|
|
|
|
|
|
const console = Scribe.create(options);
|
2016-04-11 06:16:51 -05:00
|
|
|
const logger = new Scribe.Middleware.ExpressRequestLogger(console);
|
2016-04-09 05:09:53 -05:00
|
|
|
const viewer = new Scribe.Router.Viewer(console);
|
|
|
|
|
|
|
|
console.persistent('tags', ['scribe']);
|
|
|
|
|
2016-04-11 06:16:51 -05:00
|
|
|
app.set('port', port);
|
2016-04-09 05:09:53 -05:00
|
|
|
|
|
|
|
app.use(logger.getMiddleware());
|
|
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
|
|
|
|
app.use('/', express.static(path.join(__dirname, 'public')));
|
|
|
|
|
|
|
|
app.use('/scribe', viewer.getRouter());
|
|
|
|
|
|
|
|
app.post('/', function (req, res) {
|
|
|
|
var tag = req.param('tag');
|
|
|
|
var msg = req.param('msg');
|
|
|
|
|
|
|
|
if (!msg) {
|
|
|
|
return res.status(400).send('Param `msg` not defined');
|
2016-01-22 08:22:11 -06:00
|
|
|
}
|
|
|
|
|
2016-04-09 05:09:53 -05:00
|
|
|
try {
|
|
|
|
msg = JSON.parse(msg);
|
|
|
|
} catch (e) {
|
|
|
|
// ignore
|
|
|
|
}
|
2016-01-22 08:22:11 -06:00
|
|
|
|
2016-04-09 05:09:53 -05:00
|
|
|
// print
|
|
|
|
if (tag) {
|
|
|
|
console.tag(tag).log(msg);
|
|
|
|
} else {
|
|
|
|
console.log(msg);
|
|
|
|
}
|
2016-01-22 08:22:11 -06:00
|
|
|
|
2016-04-09 05:09:53 -05:00
|
|
|
res.status(200).send("Success! Check system logs to see your message.");
|
|
|
|
});
|
2016-01-22 08:22:11 -06:00
|
|
|
|
2016-04-09 05:09:53 -05:00
|
|
|
var port = app.get('port');
|
2016-01-22 08:22:11 -06:00
|
|
|
|
2016-04-09 05:09:53 -05:00
|
|
|
//log something every 10 minutes
|
|
|
|
setInterval(function () {
|
|
|
|
console.tag("Test").log("Hi there ! Server date : " + new Date());
|
|
|
|
}, 10 * 60 * 1000);
|
2016-01-22 08:22:11 -06:00
|
|
|
|
2016-04-11 06:16:51 -05:00
|
|
|
server.listen(port, function () {
|
2016-04-09 05:09:53 -05:00
|
|
|
console.time().log('Server listening at port ' + port);
|
|
|
|
});
|
2016-01-22 08:22:11 -06:00
|
|
|
|
|
|
|
})();
|