This repository has been archived by the owner on Jun 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.js
62 lines (45 loc) · 1.76 KB
/
server.js
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
52
53
54
55
56
57
58
59
60
61
62
module.exports = function createServer(serviceLocator) {
var properties = serviceLocator.properties
, createAdaptor = require('./lib/database/create-adaptor')
, databaseAdaptor = createAdaptor(serviceLocator)
, sessionDatabaseAdaptor = createAdaptor(serviceLocator)
, bundled
, app
, bundles = require('./bundles.json')
, versionator = require('versionator').createBasic('v' + properties.version)
// Register the global services needed by your entire application
serviceLocator
.register('uploadDelegate', require('fileupload').createFileUpload(properties.dataPath))
.register('bundled', bundled = require('bundled')(serviceLocator, { logger: serviceLocator.logger }))
.register('widgetManager', require('./lib/widget-manager/widget-manager').createWidgetManager({ logger: serviceLocator.logger }))
.register('viewHelpers', {})
.register('versionator', versionator)
serviceLocator.logger.info('Starting \'' + properties.name + '\'')
bundled.addBundles(__dirname + '/bundles/',
bundles
)
app = require('./lib/web-stack')(serviceLocator, sessionDatabaseAdaptor)
serviceLocator.register('app', app)
serviceLocator.register('router', app)
databaseAdaptor.createConnection(function (error, connection) {
if (error) {
// Die the database can't be connected to
process.exit(1)
}
serviceLocator
.register('databaseConnections', {
main: connection
})
bundled.initialize(function () {
// Make the bundle manager available to views
app.locals(
{ bundled: bundled
, serviceLocator: serviceLocator
, properties: properties
})
// Add helpers
require('./lib/view-helpers.js')(serviceLocator, app)
app.start()
})
})
}