02-middleware.js 1.4 KB

// # middleware



var path = require('path');
var IoC = require('electrolyte');
var serveStatic = require('serve-static');
var bodyParser = require('body-parser');
// var winstonRequestLogger = require('winston-request-logger');
// var responseTime = require('response-time');


exports = module.exports = function (logger, settings) {

    var app = this;

    // static server (always keep this first)
    // <http://goo.gl/j2BEl5>
    app.use(serveStatic(settings.server.staticServerPath, settings.server.staticServer));

    // adds X-Response-Time header
    // app.use(responseTime({
    //     digits: 5
    // }));

    // prepare req.log for error handler
    // app.use(function (req, res, next) {
    //     req.log = {
    //         response_time: new Date().getTime(),
    //         path: req.path,
    //         query: req.query,
    //         body: req.body,
    //         params: req.params
    //     };
    //     next();
    // });

    // winston request logger before everything else
    // but only if it was enabled in settings
    // if (settings.logger.requests) {
    //     app.use(winstonRequestLogger.create(logger));
    // }

    // parse request bodies
    app.use(
        bodyParser.json({ limit: '10mb' }),
        bodyParser.urlencoded({
            limit: '10mb',
            extended: true
        })
    );
};

exports['@require'] = ['igloo/logger', 'igloo/settings'];