forked from benweet/stackedit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
38 lines (35 loc) · 1.09 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
var cluster = require('cluster');
var http = require('http');
var https = require('https');
var app = require('./app');
var count = require('os').cpus().length;
if(!process.env.NO_CLUSTER && cluster.isMaster) {
for(var i = 0; i < count; i++) {
cluster.fork();
}
cluster.on('exit', function() {
console.log('Worker died. Spawning a new process...');
cluster.fork();
});
}
else {
var port = process.env.PORT || 3000;
if(port == 443) {
// OpsWorks configuration
var fs = require('fs');
var credentials = {
key: fs.readFileSync(__dirname + '/../../shared/config/ssl.key', 'utf8'),
cert: fs.readFileSync(__dirname + '/../../shared/config/ssl.crt', 'utf8'),
ca: fs.readFileSync(__dirname + '/../../shared/config/ssl.ca', 'utf8').split('\n\n')
};
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(port, null, function() {
console.log('HTTPS server started: https://localhost');
});
port = 80;
}
var httpServer = http.createServer(app);
httpServer.listen(port, null, function() {
console.log('HTTP server started: http://localhost:' + port);
});
}