-
Notifications
You must be signed in to change notification settings - Fork 30
/
app.js
45 lines (35 loc) · 868 Bytes
/
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
/*!
* koa-react-view - example/app.js
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
*/
var staticCache = require('koa-static-cache');
var register = require('babel-register');
var react = require('..');
var path = require('path');
var koa = require('koa');
var app = koa();
var viewpath = path.join(__dirname, 'views');
var assetspath = path.join(__dirname, 'public');
react(app, { views: viewpath });
// imports babel runtime for JSX views, warning: live transpiling
// best to precompile in production deploys for perf + reliability
register({
presets: [ 'es2015', 'react' ],
extensions: [ '.jsx' ],
});
app.use(staticCache(assetspath));
app.use(function* () {
this.render('index', {
title: 'List',
list: [
'hello koa',
'hello react'
]
});
});
app.listen(3000);
console.log('server start listen at 3000');