forked from erikwco/react-isomorphic-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (49 loc) · 1.6 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Express configurations.
*
* @type {exports|module.exports}
*/
var Router = require('react-router');
var React = require('react/addons');
var express = require('express');
var Iso = require('iso');
var session = require('express-session');
var path = require('path');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
//Define Routes here
var posts = require('./routes/post.routes');
var routes = require('./src/routes.jsx');
var alt = require('./src/alt');
var app = express();
app.set('views', __dirname+'/views');
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({secret: 'copy cat', resave: false, saveUninitialized: true}));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({limit : '50mb'}));
app.use(cookieParser());
//use Routes here
app.use('/',posts);
app.use(function (req, res) {
alt.bootstrap(JSON.stringify(res.locals.data || {}));
var iso = new Iso();
Router.run(routes, req.url, function (Handler) {
var content = React.renderToString(React.createElement(Handler));
iso.add(content, alt.flush());
res.render('index',{content:iso.render()});
});
});
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
if(!err.status || err.status !== 404){
err.status = 500;
}
console.log(err);
res.status(err.status);
res.sendFile(path.resolve(__dirname+'/views/error/'+err.status+'.html'));
});
app.listen(8080, function () {
console.log('Listening on localhost:8080');
});