Skip to content

Commit

Permalink
manual rebase of balderdashy#2310 for heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Jan 28, 2015
1 parent 71f21f6 commit f38babd
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions lib/app/getBaseurl.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
/**
* Calculate the base URL
* Module dependencies
*/

var _ = require ('lodash');




/**
* Calculate the base URL (useful in emails, etc.)
* @return {String} [description]
*/

module.exports = function getBaseurl() {
var sails = this;

var usingSSL = sails.config.ssl && sails.config.ssl.key && sails.config.ssl.cert;
var host = sails.getHost() || 'localhost';
var port = sails.config.proxyPort || sails.config.port;
var localAppURL =
(usingSSL ? 'https' : 'http') + '://' +
(sails.getHost() || 'localhost') +
(port == 80 || port == 443 ? '' : ':' + port);
var probablyUsingSSL = (port === 443);

// If host doesn't contain `http*` already, include the protocol string.
var protocolString = '';
if (!_.contains(host,'http')) {
protocolString = ((usingSSL || probablyUsingSSL) ? 'https' : 'http') + '://';
}
var portString = (port === 80 || port === 443 ? '' : ':' + port);
var localAppURL = protocolString + host + portString;

return localAppURL;
};

0 comments on commit f38babd

Please sign in to comment.