forked from markfinger/python-react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
40 lines (33 loc) · 819 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var reactRender = require('react-render');
// Ensure support for JSX files
require('babel/register');
var ADDRESS = '127.0.0.1';
var PORT = 9009;
var app = express();
var server = http.Server(app);
app.use(bodyParser.json());
app.get('/', function(req, res) {
res.end('react render server');
});
app.post('/render', function(req, res) {
reactRender(req.body, function(err, markup) {
var error = null;
if (err) {
error = {
type: err.constructor.name,
message: err.message,
stack: err.stack
};
}
res.json({
error: error,
markup: markup
});
});
});
server.listen(PORT, ADDRESS, function() {
console.log('react render server listening at http://' + ADDRESS + ':' + PORT);
});