Switch to Koa, more es6
This commit is contained in:
parent
1090affc9c
commit
b3abff99ae
36 changed files with 25573 additions and 928 deletions
|
@ -1,30 +1,28 @@
|
|||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var React = require("react");
|
||||
var Router = require("react-router");
|
||||
require("node-jsx").install({extension: ".jsx"});
|
||||
var routes = require("../views/app.jsx").routes;
|
||||
import React from 'react';
|
||||
import createHandler from '../lib/react-handler';
|
||||
import {routes} from '../views/app.jsx';
|
||||
|
||||
module.exports = function(req, res, next) {
|
||||
|
||||
req.db.matches.find().sort({"created_at": -1}).limit(6).toArray().then(function(docs){
|
||||
var recents = [];
|
||||
docs.forEach(function(doc) {
|
||||
var 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;
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
Router.run(routes, req.url, function (Handler) {
|
||||
var App = React.createFactory(Handler);
|
||||
var content = React.renderToString(new App({recents: recents}));
|
||||
res.send("<!doctype html>\n" + content.replace("</body></html>", "<script>var recents = " + JSON.stringify(recents) + "</script></body></html>"));
|
||||
});
|
||||
}).catch(function(error) {
|
||||
next(error);
|
||||
});
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue