marty-express

marty-express is an express.js middleware which makes it easier to build isomorphic applications using express and react-router.

marty-express will take your react-router routes and automatically serve them as if they were in the browser meaning you have a single place to define your routes. If a user requests one of these routes, it will use app.renderToString to render the component on the server and then pass the result to the view for rendering.

If you make any requests through the HTTP state source then requests are automatically fully qualified and any HTTP headers in the original request are automatically added. It also modifies LocationStateSource and the CookieStateSource so that they use the req and res from the HTTP request.

var Marty = require('marty');
var Router = require('react-router');

var routes = [
    <Route name='foo' path='/foo/:id' handler={Foo} />,
    <Route name='var' path='/bar/:id' handler={Bar} />
];

class IsomorphicApplication extends Marty.Application {
    constructor(options) {
        super(options);

        this.register('userStore', require('./stores/userStore'));

        ...
    }
}

var app = express();

app.use(require('marty-express')({
  routes: routes,
  application: IsomorphicApplication,
  rendered: function (diagnostics) {
    console.log('Page rendered', diagnostics);
  }
}));