forked from deadvey/blogger-nodejs
Add start up checks
This commit is contained in:
@@ -11,30 +11,7 @@ const ejs = require("ejs")
|
||||
const func = require("./functions.js")
|
||||
const data = require("./data.js")
|
||||
|
||||
|
||||
// Define the modules now so they are global
|
||||
let users // contains a list of users, each user is an object containing username,prettyname,hash and description
|
||||
let posts // contains a list of posts,
|
||||
let comments // contains a list of comments
|
||||
let config // contains a set of configuration for the site, see example-config.js for an example
|
||||
|
||||
config = require('../config.json');
|
||||
if (config["data_storage"] == "json") {
|
||||
try {
|
||||
// We're going to try and import the modules,
|
||||
users = require('../data/users.json');
|
||||
posts = require('../data/posts.json');
|
||||
comments = require('../data/comments.json');
|
||||
}
|
||||
catch (error) {
|
||||
// if they don't all import then
|
||||
// inform the user to pass --first-time and exit with an error code
|
||||
console.log("A file is missing!")
|
||||
console.log("Run 'make' to initialise the data files")
|
||||
console.log(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Import the locale
|
||||
try {
|
||||
@@ -67,6 +44,45 @@ app.use('/', standard_pages_routes);
|
||||
app.use('/', forms_routes);
|
||||
app.use('/', form_actions_routes);
|
||||
|
||||
function perform_checks()
|
||||
{
|
||||
console.log("Performing startup checks...")
|
||||
exit_flag = false
|
||||
required_values = ['site_admin','seperator','site_name','site_url','locale','port','cache_data','allow_signup','site_description','request_data_limit','enable_hitcount','charset','root_path','edit_account_base_url','new_post_url','signup_url','default_commenter_username','rss','atom','date_format','time_zone','css']
|
||||
// Perform some standard checks:
|
||||
|
||||
// data_storage
|
||||
switch (config.data_storage)
|
||||
{
|
||||
case 'mysql':
|
||||
case 'json':
|
||||
break
|
||||
default:
|
||||
console.log("[ ERROR ] invalid value in `data_storage`\nPlease modify config.json. Value should be 'mysql' or 'json'.")
|
||||
exit_flag = true
|
||||
}
|
||||
// auto_generated
|
||||
if (config.auto_generated)
|
||||
{
|
||||
console.log("[ ERROR ] `autogenerated` option set to true\nplease edit the config.json file to include your relevant information, then set to false or remove the autogenerated option.")
|
||||
exit_flag = true
|
||||
}
|
||||
// Check required values are present
|
||||
required_values.forEach((value) => { // Use a loop to check each required value is present
|
||||
if (typeof config[value] == 'undefined') {
|
||||
exit_flag = true
|
||||
console.log(`[ ERROR ] \`${value}\` is undefined\nPlease set it to something, read the documentation for help.`)
|
||||
}
|
||||
});
|
||||
if (exit_flag)
|
||||
{
|
||||
console.log("Exiting due to errors.")
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
perform_checks()
|
||||
|
||||
|
||||
app.listen(config.port, () => {
|
||||
console.log(`Server is running at http://localhost:${config.port} webroot: ${config.root_path}`);
|
||||
console.log("Running in: ", __dirname)
|
||||
|
||||
Reference in New Issue
Block a user