Created
December 2, 2013 04:36
-
-
Save jimmyislive/7745146 to your computer and use it in GitHub Desktop.
Sample files to add a RSS feed to an Express/Restify setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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