combine.fm/routes/index.js

29 lines
950 B
JavaScript
Raw Normal View History

2015-06-03 21:45:54 -07:00
'use strict';
2014-12-15 12:49:17 +00:00
2015-06-03 21:45:54 -07:00
import React from 'react';
import createHandler from '../lib/react-handler';
import {routes} from '../views/app.jsx';
2014-12-15 12:49:17 +00:00
2015-06-03 21:45:54 -07:00
module.exports = function* () {
let recents = [];
let docs = yield this.db.matches.find().sort({'created_at': -1}).limit(6).toArray();
docs.forEach(function(doc) {
let shares = Object.keys(doc.services).map(function (key) {return doc.services[key]; });
shares.some(function(item) {
if (item.service === doc._id.split('$$')[0]) { // eslint-disable-line no-underscore-dangle
recents.push(item);
return false;
}
});
2014-12-15 12:49:17 +00:00
});
2015-06-03 21:45:54 -07:00
let Handler = yield createHandler(routes, this.request.url);
let App = React.createFactory(Handler);
let content = React.renderToString(new App({recents: recents}));
content = content.replace('</body></html>', '<script>var recents = ' + JSON.stringify(recents) + '</script></body></html>');
this.body = '<!doctype html>\n' + content;
2015-05-17 19:10:30 +01:00
};