2015-02-20 04:06:15 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-04-04 18:17:22 -07:00
|
|
|
var React = require('react');
|
|
|
|
|
var express = require('express');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
|
|
// Transparently support JSX
|
|
|
|
|
require('node-jsx').install();
|
|
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
|
|
// All the render server does is take a CommonJS module ID and some JSON props
|
|
|
|
|
// in the querystring and return a static HTML representation of the component.
|
|
|
|
|
// Note that this is a backend service hit by your actual web app. Even so,
|
|
|
|
|
// you would probably put Varnish in front of this in production.
|
2015-02-20 04:06:15 +03:00
|
|
|
app.get('/', function(req, res) {
|
|
|
|
|
var component = require(path.resolve(req.query.module));
|
|
|
|
|
var props = JSON.parse(req.query.props || '{}');
|
2014-04-04 18:17:22 -07:00
|
|
|
|
2015-03-09 18:15:07 -07:00
|
|
|
res.send(React.renderToString(React.createElement(component, props)));
|
2014-04-04 18:17:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.listen(3000);
|