Changed feeds endpoint to use Promise.props to make the result more reasonable to work with

This commit is contained in:
Juuso Tapaninen
2015-01-28 01:19:37 +02:00
parent 8006814e45
commit c71b3b6541
2 changed files with 6 additions and 2 deletions

View File

@@ -22,7 +22,7 @@
"bluebird": "^2.9.3",
"body-parser": "^1.10.1",
"express": "^4.11.0",
"lodash": "^2.4.1",
"lodash": "3.0.0",
"node-twitter": "0.5.2",
"superagent": "^0.21.0",
"validator": "^3.27.0"

View File

@@ -2,6 +2,7 @@
var request = require('superagent');
var cache = require('apicache').middleware;
var Promise = require('bluebird');
var twitter = require('../feeds/twitter');
var github = require('../feeds/github');
@@ -11,7 +12,10 @@ module.exports = function (app) {
* Endpoint for fetching different information feeds (Twitter, GitHub etc.)
*/
app.get('/feeds', cache('3 hours'), function(req, res, next) {
Promise.all([twitter.getTweets(), github.getEvents()]).then(function(data) {
Promise.props({
twitter: twitter.getTweets(),
github: github.getEvents()
}).then(function(data) {
res.status(200).send(data);
}, function(err) {
next(err);