-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (48 loc) · 1.68 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
var express = require("express");
var http = require('http');
var https = require('https');
var fs = require('fs');
var io = require('socket.io');
var path = require('path');
var dev = require('./bin/dev-log');
// var localtunnel = require('localtunnel');
// var ngrok = require('ngrok');
var config = require('./config.json');
module.exports = function(electronApp) {
dev.logverbose('Starting server');
var app = express();
// works without asking for a certificate
const privateKey = fs.readFileSync(path.join(__dirname, 'ssl', 'file.pem'), 'utf8');
const certificate = fs.readFileSync(path.join(__dirname, 'ssl', 'file.crt'), 'utf8');
const options = { key: privateKey, cert: certificate };
if( config.protocol === 'http')
var server = http.createServer(app);
else if( config.protocol === 'https')
var server = https.createServer(options, app);
var io = require("socket.io").listen(server);
var sockets = require('./sockets');
var expressSettings = require('./express-settings');
var router = require('./router');
var m = sockets.init(app, io, electronApp);
/*
* Server config
*/
expressSettings(app, express);
/**
* Server routing and io events
*/
router(app, io, m);
/**
* Start the http server at port and IP defined before
*/
server.listen(
app.get("port"), function() {
dev.log(`Server up and running. Go to ${config.protocol}://${config.host}:${config.port}`);
dev.log(' ');
process.on('unhandledRejection', function(reason, p) {
dev.error("Unhandled Rejection at: Promise ", p, " reason: ", reason);
// application specific logging, throwing an error, or other logic here
});
}
);
}