Skip to content

Instantly share code, notes, and snippets.

@jimmyislive
Created December 2, 2013 04:36
Show Gist options
  • Save jimmyislive/7745146 to your computer and use it in GitHub Desktop.
Save jimmyislive/7745146 to your computer and use it in GitHub Desktop.
Sample files to add a RSS feed to an Express/Restify setup
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>My title</title>
<link>https://awesomesite.com/#/</link>
<description>My Description</description>
<language>en-us</language>
<copyright>Copyright 2014, MyAwesomeSite</copyright>
<managingEditor>[email protected]</managingEditor>
<webMaster>[email protected]</webMaster>
<pubDate></pubDate>
<lastBuildDate></lastBuildDate>
<category>Technology</category>
{% for item in feed_data %}
<item>
<title>{{ item.title }}</title>
<link></link>
<description>{{ item.description }}</description>
<author>{{ item.author }}</author>
<pubDate>{{ item.pubDate }}</pubDate>
</item>
{% endfor %}
</channel>
</rss>
var cfg = require('../config').Config;
var transport = require(cfg.transportRequire);
exports.feeds = function(req, res){
var data = '';
var transportReq = transport.get(cfg.transportRequire + '://' + cfg.apiHost + ':' + cfg.apiPort + '/feeds/rss2', function(transportResponse) {
transportResponse.setEncoding('utf8');
transportResponse.on('data', function(chunk) {
data += chunk;
});
transportResponse.on('end', function(){
feed_data = JSON.parse(data);
res.setHeader('Content-Type', 'application/rss+xml');
res.render('feeds', feed_data);
});
})
transportReq.on('error', function(e) {
console.log("Got error getting feed from api server: " + e.message);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment