forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manual rebase of balderdashy#2310 for heroku
- Loading branch information
1 parent
71f21f6
commit f38babd
Showing
1 changed file
with
21 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |