02-middleware.js
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// # 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
app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }));
// parse request bodies
app.use(bodyParser.json({ limit: '10mb' }));
};
exports['@require'] = ['igloo/logger', 'igloo/settings'];