-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
31 lines (28 loc) · 808 Bytes
/
index.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
var react = require('react');
var koa = require('koa');
var koa_static = require('koa-static');
var views = require('co-views');
var app = koa();
app.use(koa_static(__dirname + '/public'));
/*********
RENDER IN MIDDLEWARE
CHANGE THIS UP IF YOU WANT TO USE A DIFFERENT TEMPLATING ENGINE
**********/
app.use(function*(next){
this.render = views('views', {
map: {
jade: 'jade'
},
default : 'jade'
});
yield next;
});
var counterComponent = require('./components/counter');
app.use(function*(next){
var opts = {count:1};
var counterHTML = react.renderComponentToString(counterComponent(opts));
this.body = yield this.render('index', {container:{counter:counterHTML}, metadata:{counter:opts}});
this.status=200;
});
app.listen(3000);
console.log('Listening on port 3000!');