-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
35 lines (29 loc) · 858 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
var JSX = require('node-jsx').install(),
React = require('react'),
TweetsApp = require('./components/TweetsApp.react'),
mongoose = require('mongoose');
Tweet = mongoose.model('Tweet');
module.exports = {
index: function(req, res) {
// Call static model method to get tweets in the db
Tweet.getTweets(0, 0, function(tweets) {
// Render React to a string, passing in the fetched tweets
var markup = React.renderComponentToString(
TweetsApp({
tweets: tweets
})
);
//Render the 'home' template
res.render('home', {
markup: markup, //Pass rendered react markup
state: JSON.stringify(tweets) //Pass curernt state to client side
});
});
},
page: function(req, res) {
// Fetch tweets by page via param
Tweet.getTweets(req.params.page, req.params.skip, function(tweets) {
res.send(tweets);
});
}
};