-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (30 loc) · 1.03 KB
/
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
require('node-cjsx').transform()
var path = require('path');
var express = require('express');
var createLocation = require('history/lib/createLocation')
var React = require('react');
var Router = require('react-router')
var routes = require('./src/routes')
var app = express();
app.set('view engine', 'jade')
app.use('/src', express.static('static/src'))
app.get('*', function (req, res) {
var location = createLocation(req.url)
Router.match({routes: routes, location: location}, function (err, redirectLoc, renderProps) {
if (redirectLoc)
res.redirect(302, redirectLoc.pathname + redirectLoc.search)
else if (err)
res.send(500, err.message)
else if (renderProps == null)
res.send(404, 'Not found')
else
res.render('index', { dom: React.renderToString(React.createElement(Router.RoutingContext, React.__spread({}, renderProps))) });
});
});
app.listen(4444, 'localhost', function (err) {
if (err) {
console.log(err);
return;
}
console.log('Listening at http://localhost:4444');
});