├── .gitignore ├── Procfile ├── Dockerfile ├── package.json ├── README.md ├── web.js └── web.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node web.js -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12-alpine 2 | COPY package* ./ 3 | RUN npm install -g foreman && npm install 4 | COPY . . 5 | EXPOSE 5000 6 | CMD ["nf", "start"] 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lorem-rss", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "web.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "BSD", 11 | "dependencies": { 12 | "crypto": "~0.0.3", 13 | "express": "^4.18.2", 14 | "lodash": "^4.17.21", 15 | "lorem-ipsum": "~0.1.1", 16 | "moment": "^2.29.4", 17 | "morgan": "^1.9.1", 18 | "rss": "^1.2.2", 19 | "seed-random": "~1.0.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lorem RSS 2 | 3 | Generates RSS feeds with content updated at regular intervals. I wrote this to 4 | answer a [question I asked on Stack Overflow](http://stackoverflow.com/questions/18202048/are-there-any-constantly-updating-rss-feed-services-to-use-for-testing-or-just). 5 | 6 | ## API 7 | 8 | Visit [http://lorem-rss.herokuapp.com/feed](http://lorem-rss.herokuapp.com/feed), with the following optional parameters: 9 | 10 | * _unit_: one of second, minute, day, month, or year 11 | * _interval_: an integer to repeat the units at. For seconds and minutes this interval must evenly divide 60, for month it must evenly divide 12, and for day and year it can only be 1. 12 | * _length_: an integer that determines the number of items in the feed. Must be greater or equal to 0 and smaller or equal to 1000. Defaults to 10 items. 13 | 14 | ## Examples 15 | 16 | * The default, updates once a minute, with 10 entries: [/feed](http://lorem-rss.herokuapp.com/feed) 17 | * Update every second instead of minute: [/feed?unit=second](http://lorem-rss.herokuapp.com/feed?unit=second) 18 | * Update every 30 seconds: [/feed?unit=second&interval=30](http://lorem-rss.herokuapp.com/feed?unit=second&interval=30) 19 | * Update once a day: [/feed?unit=day](http://lorem-rss.herokuapp.com/feed?unit=day) 20 | * Update every 6 months: [/feed?unit=month&interval=6](http://lorem-rss.herokuapp.com/feed?unit=month&interval=6) 21 | * Update once a year: [/feed?unit=year](http://lorem-rss.herokuapp.com/feed?unit=year) 22 | * Default feed with 42 entries: [/feed?length=42"](http://lorem-rss.herokuapp.com/feed?length=42) 23 | * **Invalid example:** update every 7 minutes (does not evenly divide 60): [/feed?unit=minute&interval=7](http://lorem-rss.herokuapp.com/feed?unit=minute&interval=7) 24 | 25 | ## Running locally 26 | 27 | The project contains a Dockerfile that can be used to run Lorem RSS locally. Build via: 28 | 29 | ``` 30 | docker build . -t lorem-rss 31 | ``` 32 | 33 | Run via: 34 | 35 | ``` 36 | docker run --rm -it -p 5000:5000 lorem-rss 37 | ``` 38 | 39 | With thanks given to [eelkevdbos](https://github.com/eelkevdbos), who contributed the Dockerfile. 40 | 41 | ## Copyright 42 | 43 | ### The feed and documentation 44 | 45 | Licensed by Michael Bertolacci under a Creative Commons Attribution 3.0 Unported License. 46 | 47 | ### The code 48 | 49 | The MIT License (MIT) 50 | 51 | Copyright (c) 2013 Michael Bertolacci 52 | 53 | Permission is hereby granted, free of charge, to any person obtaining a copy 54 | of this software and associated documentation files (the "Software"), to deal 55 | in the Software without restriction, including without limitation the rights 56 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 57 | copies of the Software, and to permit persons to whom the Software is 58 | furnished to do so, subject to the following conditions: 59 | 60 | The above copyright notice and this permission notice shall be included in 61 | all copies or substantial portions of the Software. 62 | 63 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 64 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 65 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 66 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 67 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 68 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 69 | THE SOFTWARE. 70 | -------------------------------------------------------------------------------- /web.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 2.5.1 2 | (function() { 3 | /* 4 | The MIT License (MIT) 5 | 6 | Copyright (c) 2013 Michael Bertolacci 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | var RSS, _, app, crypto, express, getNearest, loremIpsum, moment, morgan, port, seedRandom, units; 27 | 28 | express = require('express'); 29 | 30 | RSS = require('rss'); 31 | 32 | moment = require('moment'); 33 | 34 | _ = require('lodash'); 35 | 36 | morgan = require('morgan'); 37 | 38 | loremIpsum = require('lorem-ipsum'); 39 | 40 | seedRandom = require('seed-random'); 41 | 42 | crypto = require('crypto'); 43 | 44 | app = express(); 45 | 46 | app.use(morgan('combined')); 47 | 48 | units = { 49 | second: { 50 | nextUp: 'minute', 51 | mustDivide: 60 52 | }, 53 | minute: { 54 | nextUp: 'hour', 55 | mustDivide: 60 56 | }, 57 | hour: { 58 | nextUp: 'day', 59 | mustDivide: 24 60 | }, 61 | day: { 62 | nextUp: 'year', 63 | mustDivide: 1 64 | }, 65 | month: { 66 | nextUp: 'year', 67 | mustDivide: 12 68 | }, 69 | year: { 70 | mustDivide: 1 71 | } 72 | }; 73 | 74 | getNearest = function(interval, unit) { 75 | var now, returnDate, unitOptions; 76 | if (interval === 1) { 77 | return moment().utc().startOf(unit); 78 | } else { 79 | unitOptions = units[unit]; 80 | if (unitOptions.mustDivide % interval !== 0) { 81 | throw `When using ${unit}s the interval must divide ${unitOptions.mustDivide}`; 82 | } 83 | now = moment().utc(); 84 | returnDate = now.clone().startOf(unitOptions.nextUp || unit); 85 | returnDate[unit](now[unit]() - now[unit]() % interval); 86 | return returnDate; 87 | } 88 | }; 89 | 90 | app.get('/', function(request, response) { 91 | return response.send(` Lorem RSS

Lorem RSS

Generates RSS feeds with content updated at regular intervals. I wrote this to answer a question I asked on Stack Overflow.

The code for this service is available on GitHub.

API

Visit /feed, with the following optional parameters:

Examples


`); 92 | }); 93 | 94 | app.get('/feed', function(request, response) { 95 | var etagString, feed, i, interval, j, length, pubDate, ref, unit; 96 | if (request.query.interval != null) { 97 | interval = parseInt(request.query.interval); 98 | } else { 99 | interval = 1; 100 | } 101 | if (!interval) { 102 | response.send(500, "Interval must be an integer"); 103 | return; 104 | } 105 | if (interval <= 0) { 106 | response.send(500, "Interval must be greater than 0"); 107 | return; 108 | } 109 | unit = request.query.unit || 'minute'; 110 | if (!units[unit]) { 111 | response.send(500, `Unit must be one of ${_.keys(units).join(', ')}`); 112 | return; 113 | } 114 | length = request.query.length || 10; 115 | if (length < 0 || length > 1000) { 116 | response.send(500, "Length must be greater or equal to 0 and smaller or equal to 1000"); 117 | return; 118 | } 119 | pubDate = getNearest(interval, unit); 120 | feed = new RSS({ 121 | title: `Lorem ipsum feed for an interval of ${interval} ${unit}s with ${length} item(s)`, 122 | description: 'This is a constantly updating lorem ipsum feed', 123 | site_url: 'http://example.com/', 124 | copyright: 'Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.', 125 | ttl: Math.ceil(moment.duration(interval, unit).asMinutes()), 126 | pubDate: pubDate.clone().toDate() 127 | }); 128 | pubDate = getNearest(interval, unit); 129 | for (i = j = 0, ref = length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) { 130 | feed.item({ 131 | title: `Lorem ipsum ${pubDate.format()}`, 132 | description: loremIpsum({ 133 | random: seedRandom(pubDate.unix()) 134 | }), 135 | url: `http://example.com/test/${pubDate.format('X')}`, 136 | author: 'John Smith', 137 | date: pubDate.clone().toDate() 138 | }); 139 | pubDate = pubDate.subtract(interval, unit); 140 | } 141 | etagString = feed.pubDate + interval + unit; 142 | response.set('Content-Type', 'application/rss+xml'); 143 | response.set('ETag', `\"${crypto.createHash('md5').update(etagString).digest("hex")}\"`); 144 | return response.send(feed.xml()); 145 | }); 146 | 147 | port = process.env.PORT || 5000; 148 | 149 | app.listen(port, function() { 150 | return console.log("Listening on " + port); 151 | }); 152 | 153 | }).call(this); 154 | -------------------------------------------------------------------------------- /web.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Michael Bertolacci 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | ### 24 | 25 | express = require 'express' 26 | RSS = require 'rss' 27 | moment = require 'moment' 28 | _ = require 'lodash' 29 | morgan = require 'morgan' 30 | 31 | loremIpsum = require 'lorem-ipsum' 32 | seedRandom = require 'seed-random' 33 | crypto = require 'crypto' 34 | 35 | app = express() 36 | 37 | app.use morgan('combined') 38 | 39 | units = { 40 | second: { 41 | nextUp: 'minute', 42 | mustDivide: 60 43 | } 44 | minute: { 45 | nextUp: 'hour' 46 | mustDivide: 60 47 | } 48 | hour: { 49 | nextUp: 'day' 50 | mustDivide: 24 51 | } 52 | day: { 53 | nextUp: 'year' 54 | mustDivide: 1 55 | } 56 | month: { 57 | nextUp: 'year' 58 | mustDivide: 12 59 | } 60 | year: { 61 | mustDivide: 1 62 | } 63 | } 64 | 65 | getNearest = (interval, unit) -> 66 | if interval == 1 67 | return moment().utc().startOf(unit) 68 | else 69 | unitOptions = units[unit] 70 | if unitOptions.mustDivide % interval != 0 71 | throw "When using #{unit}s the interval must divide #{unitOptions.mustDivide}" 72 | 73 | now = moment().utc() 74 | returnDate = now.clone().startOf(unitOptions.nextUp || unit) 75 | 76 | returnDate[unit](now[unit]() - now[unit]() % interval) 77 | 78 | return returnDate 79 | 80 | app.get '/', (request, response) -> 81 | response.send """ 82 | 83 | 84 | 85 | 86 | 87 | Lorem RSS 88 | 89 | 90 | 91 | 92 | 93 | 99 | 100 | 101 |
102 |
103 |

Lorem RSS

104 |

105 | Generates RSS feeds with content updated at regular intervals. I wrote this to 106 | answer a question I asked on Stack Overflow. 107 |

108 |

109 | The code for this service is available on GitHub. 110 |

111 |

API

112 |

113 | Visit /feed, with the following optional parameters: 114 |

115 | 130 |

Examples

131 | 159 |
160 | 163 |
164 |
165 | 166 | 167 | """ 168 | 169 | 170 | app.get '/feed', (request, response) -> 171 | if request.query.interval? 172 | interval = parseInt request.query.interval 173 | else 174 | interval = 1 175 | 176 | if not interval 177 | response.send(500, "Interval must be an integer") 178 | return 179 | if interval <= 0 180 | response.send(500, "Interval must be greater than 0") 181 | return 182 | 183 | unit = request.query.unit || 'minute' 184 | 185 | if not units[unit] 186 | response.send(500, "Unit must be one of #{_.keys(units).join(', ')}") 187 | return 188 | 189 | length = request.query.length || 10 190 | 191 | if length < 0 or length > 1000 192 | response.send(500, "Length must be greater or equal to 0 and smaller or equal to 1000") 193 | return 194 | 195 | pubDate = getNearest(interval, unit) 196 | 197 | feed = new RSS({ 198 | title: "Lorem ipsum feed for an interval of #{interval} #{unit}s with #{length} item(s)", 199 | description: 'This is a constantly updating lorem ipsum feed' 200 | site_url: 'http://example.com/', 201 | copyright: 'Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.', 202 | ttl: Math.ceil(moment.duration(interval, unit).asMinutes()), 203 | pubDate: pubDate.clone().toDate() 204 | }) 205 | 206 | pubDate = getNearest(interval, unit) 207 | 208 | for i in [0...length] 209 | feed.item { 210 | title: "Lorem ipsum #{pubDate.format()}", 211 | description: loremIpsum( 212 | random: seedRandom(pubDate.unix()) 213 | ) 214 | url: "http://example.com/test/#{pubDate.format('X')}" 215 | author: 'John Smith', 216 | date: pubDate.clone().toDate() 217 | } 218 | pubDate = pubDate.subtract(interval, unit) 219 | 220 | etagString = feed.pubDate + interval + unit 221 | 222 | response.set 'Content-Type', 'application/rss+xml' 223 | response.set 'ETag', "\"#{crypto.createHash('md5').update(etagString).digest("hex");}\"" 224 | response.send feed.xml() 225 | 226 | 227 | port = process.env.PORT || 5000; 228 | 229 | app.listen port, () -> 230 | console.log("Listening on " + port); 231 | --------------------------------------------------------------------------------