Stackedit/server.js

39 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

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 {
var port = process.env.PORT || 3000;
2014-12-16 00:30:16 +00:00
if(port == 443) {
2014-12-16 01:05:23 +00:00
// OpsWorks configuration
2014-12-16 00:30:16 +00:00
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
};
2014-12-16 01:05:23 +00:00
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(port, null, function() {
console.log('HTTPS server started: https://localhost');
});
port = 80;
2014-12-16 00:30:16 +00:00
}
2014-12-16 01:05:23 +00:00
var httpServer = http.createServer(app);
httpServer.listen(port, null, function() {
console.log('HTTP server started: http://localhost:' + port);
2014-08-19 23:26:01 +00:00
});
}