forked from bcgov/mem-geo-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
62 lines (52 loc) · 1.97 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
(function () {
'use strict';
var _ = require('lodash');
var dotenv = require('dotenv');
var winston = require('winston');
var server = require('./server/app');
var repository = require('./server/repository/repository');
// Dotenv is a zero-dependency module that loads environment variables from a .env file into 'process.env'
// The .env file is for development purposes only. It should NEVER be committed to version control.
// https://github.com/motdotla/dotenv
dotenv.config();
// DEPLOYMENT CONFIGURATION
// =============================================================================
process.env.PORT = process.env.PORT || 3000;
process.env.HOST = process.env.HOST || '0.0.0.0';
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.LOG_LEVEL = process.env.LOG_LEVEL || 'debug';
process.env.SERVER_URL = process.env.SERVER_URL || 'http://localhost:4000';
process.env.PROJECT_API_PATH = process.env.PROJECT_API_PATH || '/api/projects/major';
var config = {
repo: null,
port: process.env.PORT,
host: process.env.HOST,
logger: {
level: process.env.LOG_LEVEL
},
restSettings: {
baseUrl: process.env.SERVER_URL,
path: process.env.PROJECT_API_PATH
}
};
// START THE SERVER
// =============================================================================
var rep;
repository.connect(config)
.then(function (repo) {
rep = repo;
var newConfig = _.merge({}, config, { repo: repo });
// repository connected, start the server
return server.start(newConfig);
})
.then(function (app) {
var host = app.address().address;
var port = app.address().port;
winston.info('Server started succesfully, running on http://' + host + ':' + port);
winston.info('Log level is at: ' + process.env.LOG_LEVEL);
// disconnect the repository when the server shuts down
app.on('close', function () {
rep.disconnect();
});
});
}());