From 1ebf3762504bc438feae9563f28686f8b02d0427 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Thu, 5 Mar 2020 22:08:22 -0500 Subject: [PATCH] Fixed rss caching issue --- routes/rss.js | 72 ++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/routes/rss.js b/routes/rss.js index 9b4edd7..520130e 100644 --- a/routes/rss.js +++ b/routes/rss.js @@ -4,49 +4,57 @@ const routes = require('express').Router(); const pageBuilder = require('../utils/pageBuilder'); -var feed = new RSS({ - title: 'jrtechs', - description: 'Jeffery\'s blog which has everything from data-science to cooking', - feed_url: 'https://jrtechs.net/rss', - site_url: 'https://jrtechs.net', - image_url: 'https://jrtechs.net/includes/img/favicon/android-chrome-512x512.png', - docs: 'https://github.com/jrtechs/NodeJSBlog', - managingEditor: 'Jeffery Russell', - webMaster: 'Jeffery Russell', - copyright: 'Jeffery Russell', - language: 'en', - categories: ['other', 'hardware', 'open-source', 'programming', 'projects', 'web-development', 'data-science'], -}); +const sql = require('../utils/sql'); -// var xml = require('xml'); -var xmlFeed = feed.xml(); +const generateRSSfeed = function() +{ -const sql = require('../utils/sql'); + var feed = new RSS({ + title: 'jrtechs', + description: 'Jeffery\'s blog which has everything from data-science to cooking', + feed_url: 'https://jrtechs.net/rss', + site_url: 'https://jrtechs.net', + image_url: 'https://jrtechs.net/includes/img/favicon/android-chrome-512x512.png', + docs: 'https://github.com/jrtechs/NodeJSBlog', + managingEditor: 'Jeffery Russell', + webMaster: 'Jeffery Russell', + copyright: 'Jeffery Russell', + language: 'en', + categories: ['other', 'hardware', 'open-source', 'programming', 'projects', 'web-development', 'data-science'], + }); -sql.getRecentPosts().then((data)=> -{ - for(var i = 0; i < data.length; i++) + return new Promise((resolve, reject)=> { - feed.item({ - title: data[i].name, - url: "https://jrtechs.net/" + data[i].category + "/" + data[i].url, - date: data[i].published + sql.getRecentPosts(limit=200).then((data)=> + { + for(var i = 0; i < data.length; i++) + { + feed.item({ + title: data[i].name, + url: "https://jrtechs.net/" + data[i].category + "/" + data[i].url, + date: data[i].published + }); + } + resolve(feed.xml()); + }).catch((err)=> + { + console.log(err); }); - } - xmlFeed = feed.xml(); -}).catch((err)=> -{ - console.log(err); -}); - - + }) +} routes.get('/', (request, result) => { result.set('Content-Type', 'text/xml'); - result.send(xmlFeed); + generateRSSfeed().then((data)=> + { + result.send(data); + }).catch((err)=> + { + pageBuilder.print404(result); + }) }); routes.get('*', (request, result) =>