-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.js
47 lines (39 loc) · 1.36 KB
/
index.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
'use strict';
const events = require('harken')
, pkg = require('./package.json')
, parser = require('./utils/parser')
, webSockets = require('./web-sockets')
, uuid = require('uuid')
, config = require('./utils/config')
, setup = require('./utils').setup
, routeStore = require('./routes/routeStore')
, wrapper = (configIn) => {
const configObj = config.set(configIn)
, logger = configObj.log
, routes = require(configObj.routeJSONPath);
// take care of any setup tasks before starting the server
events.once('setup:complete', () => {
const server = require('./routes/index').server(configObj.server, routes, configObj);
server.listen(configObj.port);
if (configIn.webSockets !== false) {
// enables websockets for data requests
webSockets(server, configIn.webSockets);
}
logger.info(`monument v${pkg.version} up and running on port: ${configObj.port}`);
events.emit('server:started', {
version: pkg.version
, port: configObj.port
, server: server
});
});
setup(configObj);
};
module.exports = {
server: wrapper
, events: events
, parser: parser
, routes: routeStore
, createUUID: () => {
return uuid.v4();
}
};