Skip to content

Commit

Permalink
Gets profiles rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
dzucconi committed Oct 31, 2018
1 parent c45f424 commit 37483bc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ app.use(require('../apps/examples'))
console.timeEnd('examples')

# Dynamic routing (in order)
console.time('profile')
app.use(require('../apps/profile'))
console.timeEnd('profile')

console.time('user')
app.use(require('../apps/user'))
console.timeEnd('user')
Expand Down
15 changes: 15 additions & 0 deletions apps/profile/Routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Switch, Route } from 'react-router-dom';

import parseRoute from 'react/util/parseRoute';

import ProfilePage from 'react/pages/profile/ProfilePage';

export default () => (
<Switch>
<Route
path="/profile/:id"
render={parseRoute(({ params }) => <ProfilePage id={params.id} />)}
/>
</Switch>
);
13 changes: 13 additions & 0 deletions apps/profile/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends ../../components/layout/index

block meta
!= apollo.styles

block body
#apolloMount.Constrain
!= apollo.html

block scripts
script.
window.__APOLLO_STATE__ = !{JSON.stringify(apollo.state).replace(/</g, '\\u003c')};
script( src= asset('/assets/profile.js') )
22 changes: 22 additions & 0 deletions apps/profile/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import express from 'express';

import apolloMiddleware from 'react/apollo/middleware';

import Routes from 'apps/profile/Routes';
import withStaticRouter from 'react/hocs/WithStaticRouter';

const app = express();

app
.set('views', __dirname)
.set('view engine', 'jade')

.get('/profile/:id', apolloMiddleware, (req, res, next) => {
req.apollo.render(withStaticRouter(Routes))
.then((apollo) => {
res.render('index', { apollo });
})
.catch(next);
});

module.exports = app;

0 comments on commit 37483bc

Please sign in to comment.