Add start up checks
This commit is contained in:
@@ -18,6 +18,7 @@ All options show an example configuartion value and the variable type + an expla
|
||||
| cache_data | true | Boolean | Not caching data means you can edit the posts, users, comments etc, maunally and not have to restart the server, however, for large instances this is not reccomended as it takes longer to load the required data. Note: config.json always needs a restart |
|
||||
| request_data_limit | 20 | Integer | The maximum number of objects to return (latest), so if set to 20, then only the 20 most recent posts will ever show |
|
||||
| root_path | '/var/www/blog_root' | String | Relative or Absolute path to the root directory of your static content, holds files such as favicon.ico, custom.css and robots.txt |
|
||||
| locale | 'en_GB' | String | The locale to use which determines the language used and minor cultural differences |
|
||||
## Basic Customisation
|
||||
| name | example value | variable type | explanation |
|
||||
|-----------------|----------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"dependencies": {
|
||||
"date-fns": "^4.1.0",
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^5.1.0",
|
||||
"express": "^5.2.1",
|
||||
"express-router": "^0.0.1",
|
||||
"markdown-it": "^14.1.0",
|
||||
"mysql": "^2.18.1",
|
||||
|
||||
@@ -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)
|
||||
|
||||
37
views/pages/search.ejs
Normal file
37
views/pages/search.ejs
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='<%- config.locale %>'>
|
||||
<head>
|
||||
<%- include('../partials/head'); %>
|
||||
</head>
|
||||
<body>
|
||||
<div id='site-header'>
|
||||
<%- include('../headers/site_wide'); %>
|
||||
</div>
|
||||
|
||||
<div id='advanced-search'>
|
||||
<form method="GET" action="/search">
|
||||
<label>Search Term:</label>
|
||||
<input type='text' placeholder='🔍' name='q' value='<%- search_term %>'><br/>
|
||||
|
||||
<label>Search for:</label><br/>
|
||||
<label>Post:</label>
|
||||
<input type="checkbox" name="type" value="post" <% if (search_type.includes('post')) {%>checked<% } %>><br/>
|
||||
<label>User:</label>
|
||||
<input type="checkbox" name="type" value="user" <% if (search_type.includes('user')) {%>checked<% } %>><br/>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<%- config.seperator %>
|
||||
|
||||
<div id='results'>
|
||||
<% search_results.posts.forEach((result, index) => { %>
|
||||
<a href="/post/<%- result.id %>"><%- result.title %></a><br/>
|
||||
<% }); %>
|
||||
<% search_results.users.forEach((result, index) => { %>
|
||||
<a href="/user/<%- result.username %>"><%- result.prettyname %></a><br/>
|
||||
<% }); %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user