app.js
1.6 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
// # app
var express = require('express')
var winstonRequestLogger = require('winston-request-logger')
var bootable = require('bootable')
var _ = require('underscore')
var updateNotifier = require('update-notifier')
var path = require('path')
var expressResource = require('express-resource')
exports = module.exports = function(logger, settings) {
// check for updates to all packages when not in production
if (settings.updateNotifier.enabled)
_.each(settings.pkg.dependencies, function(version, name) {
var notifier = updateNotifier({
packageName: name,
packageVersion: version,
optOut: settings.updateNotifier.dependencies[name] || false,
updateCheckInterval: settings.updateNotifier.updateCheckInterval | 1000 * 60 * 60, // hourly
updateCheckTimeout: settings.updateNotifier.updateCheckTimeout | 1000 * 20 // 20 seconds
})
if (_.isUndefined(notifier.update) || !_.isString(notifier.update.latest)) return
logger.warn(
'%s of %s released (current: %s), run `npm install -S %s@%s` to upgrade',
notifier.update.latest,
name,
version,
name,
notifier.update.latest
)
})
// create the app
var app = bootable(express())
// winston request logger before everything else
// but only if it was enabled in settings
if (settings.logger.requests)
app.use(winstonRequestLogger.create(logger))
// integrate express-resource
app = expressResource(app)
return app
}
exports['@singleton'] = true
exports['@require'] = [ 'logger', 'settings' ]