Skip to content

Commit

Permalink
🎨 show clearer error for wrong content path (#8535)
Browse files Browse the repository at this point in the history
no issue
  • Loading branch information
kirrg001 authored and aileen committed Jun 7, 2017
1 parent 216db60 commit d6d3438
Show file tree
Hide file tree
Showing 3 changed files with 21 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 @@ -43,6 +43,7 @@ _private.loadNconf = function loadNconf(options) {
nconf.isPrivacyDisabled = localUtils.isPrivacyDisabled.bind(nconf);
nconf.getContentPath = localUtils.getContentPath.bind(nconf);
nconf.sanitizeDatabaseProperties = localUtils.sanitizeDatabaseProperties.bind(nconf);
nconf.doesContentPathExist = localUtils.doesContentPathExist.bind(nconf);

nconf.sanitizeDatabaseProperties();
nconf.makePathsAbsolute(nconf.get('paths'), 'paths');
Expand All @@ -54,6 +55,11 @@ _private.loadNconf = function loadNconf(options) {
nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf);
nconf.checkUrlProtocol();

/**
* Ensure that the content path exists
*/
nconf.doesContentPathExist();

/**
* 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
@@ -1,4 +1,5 @@
var path = require('path'),
fs = require('fs-extra'),
_ = require('lodash');

exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
Expand Down Expand Up @@ -68,6 +69,16 @@ exports.getContentPath = function getContentPath(type) {
}
};

/**
* @TODO:
* - content/logs folder is required right now, otherwise Ghost want start
*/
exports.doesContentPathExist = function doesContentPathExist() {
if (!fs.pathExistsSync(this.get('paths:contentPath'))) {
throw new Error('Your content path does not exist! Please double check `paths.contentPath` in your custom config file e.g. config.production.json.');
}
};

/**
* Check if the URL in config has a protocol and sanitise it if not including a warning that it should be changed
*/
Expand Down
4 changes: 4 additions & 0 deletions core/test/unit/config/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ describe('Config', function () {
originalEnv = _.clone(process.env);
originalArgv = _.clone(process.argv);
config = rewire('../../../server/config');

// we manually call `loadConf` in the tests and we need to ensure that the minimum
// required config properties are available
process.env['paths__contentPath'] = 'content/';
});

afterEach(function () {
Expand Down

0 comments on commit d6d3438

Please sign in to comment.