fix logging and config

This commit is contained in:
Manuel Araoz 2014-08-21 17:34:15 -04:00
parent 0e5e20c09c
commit 28aeac6f9b
3 changed files with 8 additions and 23 deletions

View File

@ -3,9 +3,10 @@
/**
* Module dependencies.
*/
var express = require('express'),
config = require('./config'),
path = require('path');
var express = require('express');
var config = require('./config');
var path = require('path');
var logger = require('../lib/logger').logger;
module.exports = function(app, historicSync, peerSync) {
@ -22,11 +23,8 @@ module.exports = function(app, historicSync, peerSync) {
};
app.set('showStackError', true);
// Compress JSON outputs
app.set('json spaces', 0);
//Enable jsonp
app.enable('jsonp callback');
app.use(config.apiPrefix + '/sync', setHistoric);
app.use(config.apiPrefix + '/peer', setPeer);
@ -38,12 +36,10 @@ module.exports = function(app, historicSync, peerSync) {
if (config.publicPath) {
var staticPath = path.normalize(config.rootPath + '/../' + config.publicPath);
//IMPORTANT: for html5mode, this line must to be before app.router
app.use(express.static(staticPath));
}
// manual helpers
app.use(function(req, res, next) {
app.locals.config = config;
next();
@ -52,15 +48,10 @@ module.exports = function(app, historicSync, peerSync) {
//routes should be at the last
app.use(app.router);
//Assume "not found" in the error msgs is a 404. this is somewhat silly, but valid, you can do whatever you like, set properties, use instanceof etc.
//Assume "not found" in the error msgs is a 404
app.use(function(err, req, res, next) {
//Treat as 404
if (~err.message.indexOf('not found')) return next();
//Log it
console.error(err.stack);
//Error page
res.status(500).jsonp({
status: 500,
error: err.stack

View File

@ -94,10 +94,7 @@ var walk = function(path) {
walk(models_path);
/**
* p2pSync process
*/
// p2pSync process
var peerSync = new PeerSync({
shouldBroadcast: true
});
@ -106,9 +103,7 @@ if (!config.disableP2pSync) {
peerSync.run();
}
/**
* historic_sync process
*/
// historic_sync process
var historicSync = new HistoricSync({
shouldBroadcastSync: true
});
@ -143,8 +138,8 @@ if (config.enableMailbox) {
// express settings
require('./config/routes')(expressApp);
require('./config/express')(expressApp, historicSync, peerSync);
require('./config/routes')(expressApp);
//Start the app by listening on <port>

View File

@ -32,5 +32,4 @@ module.exports.init = function(app, config) {
}
}
}));
};