add hikes/map pulls hikes out of db and renders

This commit is contained in:
Berkeley Martinez
2015-07-13 00:25:01 -07:00
parent 8f738fb1d0
commit de1d931b82
13 changed files with 161 additions and 54 deletions

View File

@@ -3,7 +3,7 @@ import Router from 'react-router';
import Location from 'react-router/lib/Location';
import debugFactory from 'debug';
import { app$ } from '../../common/app';
import { Cat } from 'thundercats';
import { RenderToString } from 'thundercats-react';
const debug = debugFactory('freecc:servereact');
@@ -25,23 +25,23 @@ export default function reactSubRouter(app) {
app.use(router);
function serveReactApp(req, res, next) {
const fcc = new Cat();
const location = new Location(req.path, req.query);
// returns a router wrapped app
app$(location)
// if react-router does not find a route send down the chain
.filter(function([ initialState ]) {
.filter(function({ initialState }) {
if (!initialState) {
debug('tried to find %s but got 404', location.pathname);
return next();
}
return !!initialState;
})
.flatMap(function([ initialState ]) {
.flatMap(function({ initialState, AppCat }) {
// call thundercats renderToString
// prefetches data and sets up it up for current state
return fcc.renderToString(
return RenderToString(
AppCat(),
React.createElement(Router, initialState)
);
})