-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
41 lines (34 loc) · 929 Bytes
/
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
'use strict';
var server = require('./lib/server/')();
var config = require('config');
function ngrokIsAvailable() {
try {
require.resolve('ngrok');
return true;
} catch (e) {
return false;
}
}
/**
* Make sure to configuration is valid before attempting to start the server.
*/
if (!config.isValid()) {
config.getConfigValidityReport().errors.forEach(function(error){
console.log(error);
});
console.error("\n\nInvalid configuration detected. Aborted server startup.\n");
return;
}
var port = config.get("port") || 8080;
server.listen(port, function () {
console.log('listening on port ' + port);
if (process.env.NODE_ENV === 'development' && ngrokIsAvailable()) {
require('ngrok').connect(port, function (err, url) {
if (err) {
console.error('ngrok error', err);
return;
}
console.log('publicly accessible https url is: ' + url);
});
}
});