-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (35 loc) · 1.22 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
var rekuire = require('rekuire');
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var morgan = require('morgan');
var intel = require('intel');
var Promise = require('bluebird');
var _ = require('lodash');
var fs = require('fs');
var configuration = rekuire('configuration/configuration');
intel.basicConfig({
format: '[%(date)s] %(name)s:: %(message)s',
level : configuration.getLogLevel()
});
var logger = rekuire('utils/LoggerProvider').getLogger();
var readDirPromise = rekuire('utils/ReadDirPromise');
// Load all models before starting the server
var normalizedPath = path.join(__dirname, "models/");
readDirPromise(normalizedPath).then(function(models) {
return Promise.all(
_.map(models, function(model) {
require( path.join(normalizedPath, model) );
})
);
}).then(function() {
// Prepare server
var app = express();
app.use(bodyParser.json());
app.use(morgan('common'));
// Setup routes (base entry point)
app.use(configuration.getAPIBasePath() + '/v1', require('./routes/v1/api'));
// Start listening
app.listen(configuration.getServerPort());
logger.info('API is running on port ' + configuration.getServerPort());
});