diff options
-rw-r--r-- | package-lock.json | 29 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/server.js | 24 |
3 files changed, 54 insertions, 0 deletions
diff --git a/package-lock.json b/package-lock.json index 5e777ad..fa106aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -931,6 +931,30 @@ "any-promise": "^1.3.0" } }, + "rss": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/rss/-/rss-1.2.2.tgz", + "integrity": "sha1-UKFpiHYTgTOnT5oF0r3I240nqSE=", + "requires": { + "mime-types": "2.1.13", + "xml": "1.0.1" + }, + "dependencies": { + "mime-db": { + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.25.0.tgz", + "integrity": "sha1-wY29fHOl2/b0SgJNwNFloeexw5I=" + }, + "mime-types": { + "version": "2.1.13", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.13.tgz", + "integrity": "sha1-4HqqnGxrmnyjASxpADrSWjnpKog=", + "requires": { + "mime-db": "~1.25.0" + } + } + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -1206,6 +1230,11 @@ "@types/node": "*" } }, + "xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=" + }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 27c1eb4..13885fc 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "multer": "^1.4.2", "mysql2": "^1.7.0", "request": "^2.88.0", + "rss": "^1.2.2", "sequelize": "^5.21.4", "uuid": "^3.3.3" } diff --git a/src/server.js b/src/server.js index 0d01641..7a21525 100644 --- a/src/server.js +++ b/src/server.js @@ -5,6 +5,7 @@ const request = require('request'); const crypto = require('crypto'); const uuidv4 = require('uuid/v4'); const path = require('path'); +const rss = require('rss'); const Op = require('sequelize').Op; @@ -284,6 +285,29 @@ function setUpRoutes(models, jwtFunctions, database) { res.sendFile(__dirname + "/js/" + req.params.id); }); + server.get('/feed.xml', async (req, res) => { + var feed = new rss({ + title: "Mark's Kitchen", + description: "Posts from marks.kitchen", + feed_url: "https://marks.kitchen/rss", + site_url: "https://marks.kitchen", + webMaster: "webmaster@marks.kitchen", + copyright: "Mark Powers" + }) + var posts = await models.posts.findAll({ + order: [['createdAt', 'DESC']] + }); + posts = posts.map(x => x.get({ plain: true })); + posts.forEach(post =>{ + feed.item({ + title: post.createdAt.toString().substring(0, post.createdAt.toString().indexOf(" GMT")), + description: post.description, + date: post.createdAt, + url: `https://marks.kitchen/post/${post.type}/${post.id}`, + }) + }) + res.status(200).send(feed.xml({indent: true})) + }) } module.exports = { |