From fc7bc63c46ec7fa0ddcd03f47ec60c30dc6a6933 Mon Sep 17 00:00:00 2001 From: Klemek Date: Wed, 26 Jun 2019 19:44:52 +0200 Subject: [PATCH 1/2] Nodemon config --- README.md | 8 ++++++++ package.json | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0466fc2..ad9d597 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,14 @@ Here are the steps for Github, if you use another platform adapt it your way (he * Update your webhook on github to include the secret * Check if Github successfully reached the endpoint +#### 8. Keep your server always up and running (optionnal) + +This project `package.json` comes with a [nodemon](https://github.com/remy/nodemon) config. + +After installing (`npm i -g nodemon`) you can then run the app with juste the `nodemon` command in the working directory. + +With this method, you can do a simple `git pull` to update your server. + ## Writing an article [back to top](#gitblog-md) diff --git a/package.json b/package.json index 1a1d5e8..13fdb88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitblog.md", - "version": "1.2.1", + "version": "1.2.2", "description": "A static blog using Markdown pulled from your git repository.", "main": "src/server.js", "dependencies": { @@ -46,5 +46,16 @@ "!src/postinstall.js", "!src/lib/*.js" ] + }, + "nodemonConfig": { + "ignore": [ + "test/*", + "sample_data/*", + "data/*", + "uml/*", + "*.log", + "README.md" + ], + "delay": "2500" } } From 52d37d56cdd9ae93d16a957d5f7b7e12fecf66ba Mon Sep 17 00:00:00 2001 From: Klemek Date: Wed, 26 Jun 2019 19:48:51 +0200 Subject: [PATCH 2/2] Bug fix --- src/app.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app.js b/src/app.js index 3d7a118..122ad10 100644 --- a/src/app.js +++ b/src/app.js @@ -94,17 +94,16 @@ module.exports = (config) => { /** * Show an error with the correct page * @param req - * @param resPath - the page of the original error - * @param code - error code * @param res + * @param code - error code */ - const showError = (req, resPath, code, res) => { + const showError = (req, res, code) => { const errorPath = path.join(config['data_dir'], config['home']['error']); fs.access(errorPath, fs.constants.R_OK, (err) => { if (err) res.sendStatus(code); else - render(req, res, errorPath, {error: code, path: resPath}, code); + render(req, res, errorPath, {error: code, path: req.path}, code); }); }; @@ -137,7 +136,7 @@ module.exports = (config) => { const homePath = path.join(config['data_dir'], config['home']['index']); fs.access(homePath, fs.constants.R_OK, (err) => { if (err) - showError(req.path, 404, res); + showError(req, res, 404); else render(req, res, homePath, {articles: Object.values(articles).sort((a, b) => ('' + b.path).localeCompare(a.path))}); }); @@ -150,15 +149,15 @@ module.exports = (config) => { const feed = new Rss({ 'title': config['rss']['title'], 'description': config['rss']['description'], - 'feed_url': 'http://' + req.headers.host + req.url, - 'site_url': 'http://' + req.headers.host + 'feed_url': host + req.url, + 'site_url': host }); Object.values(articles) .slice(0, config['rss']['length']) .forEach((article) => { feed.item({ title: article.title, - url: 'http://' + req.headers.host + article.url, + url: host + article.url, date: article.date }); }); @@ -166,7 +165,7 @@ module.exports = (config) => { } res.type(req.headers['user-agent'].match(/Mozilla/) ? 'text/xml' : 'rss').send(lastRSS); } else { - showError(req.path, 404, res); + showError(req, res, 404); } }); @@ -209,19 +208,19 @@ module.exports = (config) => { const articlePath = req.path.substr(1, 10); const article = articles[articlePath]; if (!article) - showError(req.path, 404, res); + showError(req, res, 404); else { renderer.render(path.join(article.realPath, config['article']['index']), (err, html) => { if (err) { console.log(cons.error, `failed to render article ${req.path} : ${err}`); - return showError(req.path, 500, res); + return showError(req, res, 500); } article.content = html; const templatePath = path.join(config['data_dir'], config['article']['template']); fs.access(templatePath, fs.constants.R_OK, (err) => { if (err) { console.log(cons.error, `no template found at ${templatePath}`); - showError(req.path, 500, res); + showError(req, res, 500); } else render(req, res, templatePath, {article: article}); }); @@ -235,7 +234,7 @@ module.exports = (config) => { // catch all hidden file type and return 404 app.get('*', (req, res, next) => { if (config['home']['hidden'].includes(path.extname(req.path))) - showError(req.path, 404, res); + showError(req, res, 404); else next(); }); @@ -244,7 +243,7 @@ module.exports = (config) => { app.get('*', express.static(path.join(__dirname, '..', config['data_dir']))); // catch express.static errors (mostly not found) by displaying 404 app.get('*', (req, res) => { - showError(req.path, 404, res); + showError(req, res, 404); }); // catch all other methods and return 400