forked from barankyle/lifescope-embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (39 loc) · 1.23 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
let mongodb = require('mongodb');
let app = require('./app');
let sysUtils = require('./utils');
module.exports = (async function() {
var server = app.listen(process.env.PORT || CONFIG.port, process.env.HOST || CONFIG.host, function() {
console.log('\niframely is running on ' + server.address().address + ':' + server.address().port);
console.log('API endpoints: /oembed and /iframely; Debugger UI: /debug\n');
});
let mongo;
try {
mongo = await mongodb.MongoClient.connect(CONFIG.mongo.address, CONFIG.mongo.options);
} catch(err) {
console.log(err);
mongo = null;
}
global.env = {
mongo: mongo
};
if (CONFIG.ssl) {
require('https').createServer(CONFIG.ssl, app).listen(CONFIG.ssl.port);
}
// console.log('');
// console.log(' - [email protected] - if you need help');
// console.log(' - twitter.com/iframely - news & updates');
// console.log(' - github.com/itteco/iframely - star & contribute');
if (!CONFIG.DEBUG) {
var GracefulServer = require('graceful-cluster').GracefulServer;
new GracefulServer({
server: server,
log: sysUtils.log,
shutdownTimeout: CONFIG.SHUTDOWN_TIMEOUT
});
}
return Promise.resolve(global.env);
})()
.catch(function(err) {
console.log(err);
process.exit(1);
});