-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
37 lines (28 loc) · 811 Bytes
/
routes.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
var Tweet = require('./models/Tweet'),
config = require('./config'),
JSX = require('node-jsx').install(),
React = require('react'),
twtApp = React.createFactory(require('./jsx/main'));
module.exports = {
index: function(req, res) {
var tweets = [];
var markup = "";
//get 10 last tweets from the DB.
Tweet.find({}).sort({date: '-1'}).limit(10).exec(function(err, fromDb) {
if(!err) {
// because why the fuck not.
tweets = JSON.parse(JSON.stringify(fromDb));
//Server side render.
markup = React.renderToString(twtApp({tweets: tweets}));
res.render('home.handlebars', {
markup: markup,
state: JSON.stringify(tweets),
mode: config.mode
});
} else {
console.log(err);
res.status(500).send("something went wrong..");
}
})
}
}