Repository: ignite Updated Branches: refs/heads/ignite-843 2e9d239e0 -> 745a55f2e
ignite-843 SSL fixed Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/745a55f2 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/745a55f2 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/745a55f2 Branch: refs/heads/ignite-843 Commit: 745a55f2ea08fb873abe52a73da6701e4f1e49c6 Parents: 2e9d239 Author: Andrey <[email protected]> Authored: Fri Oct 9 08:35:57 2015 +0700 Committer: Andrey <[email protected]> Committed: Fri Oct 9 08:35:57 2015 +0700 ---------------------------------------------------------------------- modules/control-center-web/src/main/js/app.js | 33 +++++++++----------- modules/control-center-web/src/main/js/bin/www | 32 ++----------------- .../src/main/js/helpers/configuration-loader.js | 21 ++++++++++++- 3 files changed, 36 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/745a55f2/modules/control-center-web/src/main/js/app.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/app.js b/modules/control-center-web/src/main/js/app.js index 6bba806..e4dd654 100644 --- a/modules/control-center-web/src/main/js/app.js +++ b/modules/control-center-web/src/main/js/app.js @@ -24,6 +24,8 @@ var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var session = require('express-session'); var mongoStore = require('connect-mongo')(session); +var forceSSL = require('express-force-ssl'); +var config = require('./helpers/configuration-loader.js'); var publicRoutes = require('./routes/public'); var notebooksRoutes = require('./routes/notebooks'); @@ -92,6 +94,18 @@ passport.deserializeUser(db.Account.deserializeUser()); passport.use(db.Account.createStrategy()); +if (config.get('server:ssl')) { + var httpsPort = config.normalizePort(config.get('server:https-port') || 443); + + app.set('forceSSLOptions', { + enable301Redirects: true, + trustXFPHeader: true, + httpsPort: httpsPort + }); + + app.use(forceSSL); +} + var mustAuthenticated = function (req, res, next) { req.isAuthenticated() ? next() : res.redirect('/'); }; @@ -171,23 +185,4 @@ app.use(function (err, req, res) { }); }); -/** - * Normalize a port into a number, string, or false. - */ -function normalizePort(val) { - var port = parseInt(val, 10); - - if (isNaN(port)) { - // named pipe - return val; - } - - if (port >= 0) { - // port number - return port; - } - - return false; -} - module.exports = app; http://git-wip-us.apache.org/repos/asf/ignite/blob/745a55f2/modules/control-center-web/src/main/js/bin/www ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/bin/www b/modules/control-center-web/src/main/js/bin/www index 289be0b..0340cb0 100644 --- a/modules/control-center-web/src/main/js/bin/www +++ b/modules/control-center-web/src/main/js/bin/www @@ -7,7 +7,6 @@ var http = require('http'); var https = require('https'); var config = require('../helpers/configuration-loader.js'); var app = require('../app'); -var forceSSL = require('express-force-ssl'); var agentManager = require('../agents/agent-manager'); var fs = require('fs'); @@ -17,7 +16,7 @@ var debug = require('debug')('ignite-web-console:server'); /** * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || config.get('server:port')); +var port = config.normalizePort(config.get('server:port') || process.env.PORT || 80); // Create HTTP server. var server = http.createServer(app); @@ -38,15 +37,7 @@ if (config.get('server:ssl')) { passphrase: config.get('server:keyPassphrase') }, app); - var httpsPort = normalizePort(process.env.PORT || config.get('server:https-port')); - - app.set('forceSSLOptions', { - enable301Redirects: true, - trustXFPHeader: true, - httpsPort: httpsPort - }); - - app.use(forceSSL); + var httpsPort = config.normalizePort(config.get('server:https-port') || 443); /** * Listen on provided port, on all network interfaces. @@ -77,25 +68,6 @@ agentServer.listen(config.get('agent-server:port')); agentManager.createManager(agentServer); /** - * Normalize a port into a number, string, or false. - */ -function normalizePort(val) { - var port = parseInt(val, 10); - - if (isNaN(port)) { - // named pipe - return val; - } - - if (port >= 0) { - // port number - return port; - } - - return false; -} - -/** * Event listener for HTTP server "error" event. */ function onError(error) { http://git-wip-us.apache.org/repos/asf/ignite/blob/745a55f2/modules/control-center-web/src/main/js/helpers/configuration-loader.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/helpers/configuration-loader.js b/modules/control-center-web/src/main/js/helpers/configuration-loader.js index 6dbb577..6918297 100644 --- a/modules/control-center-web/src/main/js/helpers/configuration-loader.js +++ b/modules/control-center-web/src/main/js/helpers/configuration-loader.js @@ -19,4 +19,23 @@ var config = require('nconf'); config.file({'file': 'config/default.json'}); -module.exports = config; \ No newline at end of file +/** + * Normalize a port into a number, string, or false. + */ +config.normalizePort = function (val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +}; + +module.exports = config;
