2014-08-19 23:26:01 +00:00
|
|
|
var cluster = require('cluster');
|
2014-12-16 00:30:16 +00:00
|
|
|
var http = require('http');
|
|
|
|
var https = require('https');
|
2014-08-13 21:06:14 +00:00
|
|
|
var app = require('./app');
|
2013-10-19 22:59:17 +00:00
|
|
|
|
2014-08-19 23:26:01 +00:00
|
|
|
var count = require('os').cpus().length;
|
|
|
|
|
|
|
|
if(!process.env.NO_CLUSTER && cluster.isMaster) {
|
|
|
|
for(var i = 0; i < count; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
2014-08-31 19:51:13 +00:00
|
|
|
cluster.on('exit', function() {
|
2014-08-19 23:26:01 +00:00
|
|
|
console.log('Worker died. Spawning a new process...');
|
|
|
|
cluster.fork();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2014-12-16 00:30:16 +00:00
|
|
|
var server;
|
2014-08-19 23:26:01 +00:00
|
|
|
var port = process.env.PORT || 3000;
|
2014-12-16 00:30:16 +00:00
|
|
|
if(port == 443) {
|
|
|
|
// Configure HTTPS on OpsWorks
|
|
|
|
var fs = require('fs');
|
|
|
|
var credentials = {
|
2014-12-16 00:51:00 +00:00
|
|
|
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')
|
2014-12-16 00:30:16 +00:00
|
|
|
};
|
|
|
|
server = https.createServer(credentials, app);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
server = http.createServer(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
server.listen(port, null, function() {
|
2014-08-19 23:26:01 +00:00
|
|
|
console.log('Server started: http://localhost:' + port);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|