forked from TryGhost/Ghost
-
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.
Refactor the initial boot of Ghost, allowing Ghost updates to keep cu…
…rrent configuration intact. Extracts all express-server-related code in index.js to core/server.js, leaving index.js purely for booting up Ghost's core components in a sensible order. Aside from the project's tidiness, this means that we can perform asynchronous configuration loading/checks before requiring any modules that read the config.
- Loading branch information
1 parent
5f0d8c6
commit c5fa7ae
Showing
6 changed files
with
447 additions
and
291 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
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// # Ghost Configuration | ||
|
||
var path = require('path'), | ||
config; | ||
|
||
// ## Environment | ||
// **Warning:** Only change the settings below here if you are sure of what you are doing! | ||
config = { | ||
testing: { | ||
database: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: path.join(__dirname, '/core/server/data/ghost-test.db') | ||
} | ||
}, | ||
server: { | ||
host: '127.0.0.1', | ||
port: '2369' | ||
}, | ||
// The url to use when providing links to the site; like RSS and email. | ||
url: 'http://127.0.0.1:2369' | ||
}, | ||
|
||
travis: { | ||
database: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: path.join(__dirname, '/core/server/data/ghost-travis.db') | ||
} | ||
}, | ||
server: { | ||
host: '127.0.0.1', | ||
port: '2368' | ||
}, | ||
// The url to use when providing links to the site; like RSS and email. | ||
url: 'http://127.0.0.1:2368' | ||
}, | ||
|
||
// Default configuration | ||
development: { | ||
database: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: path.join(__dirname, '/core/server/data/ghost-dev.db') | ||
}, | ||
debug: false | ||
}, | ||
server: { | ||
host: '127.0.0.1', | ||
port: '2368' | ||
}, | ||
// The url to use when providing links to the site; like RSS and email. | ||
url: 'http://127.0.0.1:2368', | ||
// Example mail config | ||
mail: { | ||
transport: 'sendgrid', | ||
host: 'smtp.sendgrid.net', | ||
options: { | ||
service: 'Sendgrid', | ||
auth: { | ||
user: '', // Super secret username | ||
pass: '' // Super secret password | ||
} | ||
} | ||
} | ||
}, | ||
|
||
staging: { | ||
database: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: path.join(__dirname, '/core/server/data/ghost-staging.db') | ||
}, | ||
debug: false | ||
}, | ||
server: { | ||
host: '127.0.0.1', | ||
port: '2368' | ||
}, | ||
// The url to use when providing links to the site; like RSS and email. | ||
url: 'http://127.0.0.1:2368' | ||
}, | ||
|
||
production: { | ||
database: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: path.join(__dirname, '/core/server/data/ghost.db') | ||
}, | ||
debug: false | ||
}, | ||
server: { | ||
host: '127.0.0.1', | ||
port: '2368' | ||
}, | ||
// The url to use when providing links to the site; like RSS and email. | ||
url: 'http://127.0.0.1:2368' | ||
} | ||
}; | ||
|
||
// Export config | ||
module.exports = config; |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var fs = require('fs'), | ||
when = require('when'); | ||
|
||
function writeConfigFile() { | ||
var written = when.defer(); | ||
|
||
/* Check for config file and copy from config.example.js | ||
if one doesn't exist. After that, start the server. */ | ||
fs.exists('config.example.js', function checkTemplate(templateExists) { | ||
var read, | ||
write; | ||
|
||
if (!templateExists) { | ||
throw new Error('Could not locate a configuration file. Please check your deployment for config.js or config.example.js.'); | ||
} | ||
|
||
// Copy config.example.js => config.js | ||
read = fs.createReadStream('config.example.js'); | ||
read.on('error', function (err) { | ||
throw new Error('Could not open config.example.js for read.'); | ||
}); | ||
read.on('end', written.resolve); | ||
|
||
write = fs.createWriteStream('config.js'); | ||
write.on('error', function (err) { | ||
throw new Error('Could not open config.js for write.'); | ||
}); | ||
|
||
read.pipe(write); | ||
}); | ||
|
||
return written.promise; | ||
} | ||
|
||
exports.loadConfig = function () { | ||
var loaded = when.defer(); | ||
/* Check for config file and copy from config.example.js | ||
if one doesn't exist. After that, start the server. */ | ||
fs.exists('config.js', function checkConfig(configExists) { | ||
if (configExists) { | ||
loaded.resolve(); | ||
} else { | ||
writeConfigFile().then(loaded.resolve).otherwise(loaded.reject); | ||
} | ||
}); | ||
return loaded.promise; | ||
}; |
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
Oops, something went wrong.