feature(cloudcmd) drop ssl suport

This commit is contained in:
coderaiser 2014-09-08 06:02:12 -04:00
parent 4e59f4c16e
commit 30e4905ffd
5 changed files with 7 additions and 62 deletions

View file

@ -20,7 +20,6 @@
URL = require('url'),
path = require('path'),
http = require('http'),
https = require('https'),
Util = require(DIR_LIB + 'util'),
CloudFunc = require(DIR_LIB + 'cloudfunc'),
@ -64,9 +63,8 @@
* @param options
*/
function start(options) {
var redirectServer, port, ip, ssl, sslPort,
var port, ip,
HTTP = 'http://',
HTTPS = 'https://',
config = main.config;
if (!options)
@ -78,48 +76,16 @@
port = process.env.PORT || /* c9 */
process.env.VCAP_APP_PORT || /* cloudfoundry */
config.port,
ip = process.env.IP || /* c9 */
config.ip ||
'0.0.0.0',
ssl = options.ssl,
sslPort = config.sslPort;
'0.0.0.0';
if (config.server)
if (!ssl)
createServer(port, ip, HTTP);
else {
createRedirect(port, ip, HTTPS, sslPort);
createServer(sslPort, ip, HTTP, ssl, function() {
Util.log('Could not use https port: ' + sslPort);
redirectServer.close();
Util.log('* Redirection http -> https removed');
createServer(port, ip);
});
}
createServer(port, ip, HTTP);
}
function createRedirect(port, ip, protocol, sslPort) {
var server = function(req, res) {
var url,
host = req.headers.host,
parsed = URL.parse(host),
hostName = parsed.protocol;
url = protocol + hostName + sslPort + req.url;
ponse.redirect(url, res);
};
Util.log('* Redirection http -> https is setted up');
logServer(port, ip, protocol);
http.createServer(server)
.listen(port, ip);
}
function createServer(port, ip, protocol, ssl, callback) {
function createServer(port, ip, protocol, callback) {
var server, app, respondApp,
config = main.config,
@ -163,10 +129,7 @@
app = respondApp;
}
if (ssl)
server = https.createServer(ssl, app);
else
server = http.createServer(app);
server = http.createServer(app);
server.on('error', function(error) {
Util.log(error);