Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80743 views
1
'use strict';
2
3
var React = require('react');
4
var express = require('express');
5
var path = require('path');
6
7
// Transparently support JSX
8
require('node-jsx').install();
9
10
var app = express();
11
12
// All the render server does is take a CommonJS module ID and some JSON props
13
// in the querystring and return a static HTML representation of the component.
14
// Note that this is a backend service hit by your actual web app. Even so,
15
// you would probably put Varnish in front of this in production.
16
app.get('/', function(req, res) {
17
var component = require(path.resolve(req.query.module));
18
var props = JSON.parse(req.query.props || '{}');
19
20
res.send(React.renderToString(React.createElement(component, props)));
21
});
22
23
app.listen(3000);
24
25