Skip to content

Commit

Permalink
⚡️ Throw clear error message when config.url has no protocol (#8466)
Browse files Browse the repository at this point in the history
closes #8449

- throw a more clear error message
  • Loading branch information
aileen authored and kirrg001 committed May 21, 2017
1 parent fc89cf1 commit c7bbaff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/server/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ _private.loadNconf = function loadNconf(options) {
nconf.makePathsAbsolute(nconf.get('paths'), 'paths');
nconf.makePathsAbsolute(nconf.get('database:connection'), 'database:connection');

/**
* Check if the URL in config has a protocol
*/
nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf);
nconf.checkUrlProtocol();

/**
* values we have to set manual
*/
Expand Down
11 changes: 11 additions & 0 deletions core/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ exports.getContentPath = function getContentPath(type) {
}
};

/**
* Check if the URL in config has a protocol and sanitise it if not including a warning that it should be changed
*/
exports.checkUrlProtocol = function checkUrlProtocol() {
var url = this.get('url');

if (!url.match(/^https?:\/\//i)) {
throw new Error('URL in config must be provided with protocol, eg. "http://my-ghost-blog.com"');
}
};

/**
* nconf merges all database keys together and this can be confusing
* e.g. production default database is sqlite, but you override the configuration with mysql
Expand Down

0 comments on commit c7bbaff

Please sign in to comment.