import React from 'react';
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path';

/**
 * Set up Express.
 */
const app = express();
app.use(bodyParser.json());

/**
 * Simple error handler.
 */
app.use(function(err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});

app.use('/:component', function(request, response) {
  const component = require(`./components/${request.params.component}`);
  const props = request.body || null;

  response.status(200).send(
    React.renderToString(
      React.createElement(component, props)
    )
  );
});

export default app;


import React from 'react';
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path';

/**
 * Set up Express.
 */
const app = express();
app.use(bodyParser.json({ limit: '10mb' }));

/**
 * Simple error handler.
 */
app.use(function(err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});

/**
 * Request pre-rendered markup for a given component
 * with JSON props data.
 *
 * POST /:component
 */
app.use('/:component', function(request, response) {
  const component = require(`./components/${request.params.component}`);
  const props = request.body || null;

  response.status(200).send(
    React.renderToString(
      React.createElement(component, props)
    )
  );
});

export default app;


Increase maximum request size for rendered process.