2017-09-28 04:27:12 +08:00
|
|
|
process.env.NODE_ENV = 'production';
|
|
|
|
|
2017-09-27 06:54:26 +08:00
|
|
|
var cluster = require('cluster');
|
|
|
|
var http = require('http');
|
|
|
|
var https = require('https');
|
|
|
|
var path = require('path');
|
|
|
|
var express = require('express');
|
|
|
|
var app = express();
|
|
|
|
|
2017-09-30 02:43:26 +08:00
|
|
|
require('./server')(app, process.env.SERVE_V4);
|
2017-09-27 06:54:26 +08:00
|
|
|
|
2017-09-28 04:27:12 +08:00
|
|
|
var port = parseInt(process.env.PORT || 8080, 10);
|
2017-09-27 06:54:26 +08:00
|
|
|
if(port === 443) {
|
|
|
|
var fs = require('fs');
|
|
|
|
var credentials = {
|
2017-09-28 04:27:12 +08:00
|
|
|
key: fs.readFileSync(path.join(__dirname, 'ssl.key'), 'utf8'),
|
|
|
|
cert: fs.readFileSync(path.join(__dirname, 'ssl.crt'), 'utf8'),
|
|
|
|
ca: fs.readFileSync(path.join(__dirname, 'ssl.ca'), 'utf8').split('\n\n')
|
2017-09-27 06:54:26 +08:00
|
|
|
};
|
|
|
|
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);
|
|
|
|
});
|