-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
113 lines (93 loc) · 2.96 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var koa = require('koa');
var controller = require('koa-route');
var app = koa();
var views = require('co-views');
var querystring = require('querystring');
var render = views('./view',{
map : {html : 'ejs'}
});
var koa_static = require('koa-static-server');
var service = require('./service/webAppService.js');
app.use(koa_static({
rootDir: './static/',
rootPath: '/static/',
maxage: 0
}))
app.use(controller.get('/route_test', function*(){
this.set('Cache-Control', 'no-cache');
this.body = "hello world";
}))
app.use(controller.get('/ejs_test', function*(){
this.set('Cache-Control', 'no-cache');
this.body = yield render('test',{title:'title_test'});
}))
app.use(controller.get('/api_test', function*(){
this.set('Cache-Control', 'no-cache');
var content = service.get_test_data();
this.body = service.get_test_data();
}))
app.use(controller.get('/', function*(){
this.set('Cache-Control', 'no-cache');
this.body = yield render('index',{title:'书城首页'});
}))
app.use(controller.get('/search', function*(){
this.set('Cache-Control', 'no-cache');
this.body = yield render('search',{title:'搜索页面'});
}))
app.use(controller.get('/reader', function*(){
this.set('Cache-Control', 'no-cache');
this.body = yield render('reader');
}))
app.use(controller.get('/book', function*(){
this.set('Cache-Control', 'no-cache');
var params = querystring.parse(this.req._parsedUrl.query);
var bookId = params.id;
this.body = yield render('book',{nav:'书籍详情',bookId:bookId});
}))
app.use(controller.get('/ajax/index', function*(){
this.set('Cache-Control', 'no-cache');
this.body = service.get_index_data();
}))
app.use(controller.get('/ajax/rank', function*(){
this.set('Cache-Control', 'no-cache');
this.body = service.get_rank_data();
}))
app.use(controller.get('/ajax/female', function*(){
this.set('Cache-Control', 'no-cache');
this.body = service.get_female_data();
}))
app.use(controller.get('/ajax/male', function*(){
this.set('Cache-Control', 'no-cache');
this.body = service.get_male_data();
}))
app.use(controller.get('/ajax/category', function*(){
this.set('Cache-Control', 'no-cache');
this.body = service.get_category_data();
}))
app.use(controller.get('/ajax/bookbcaket', function*(){
this.set('Cache-Control', 'no-cache');
this.body = service.get_bookcaket_data();
}))
app.use(controller.get('/ajax/book', function*(){
this.set('Cache-Control', 'no-cache');
var params = querystring.parse(this.req._parsedUrl.query);
var id = params.id;
if(!id){
id = "";
}
this.body = service.get_book_data(id);
}))
app.use(controller.get('/ajax/chapter', function*(){
this.body = service.get_chapter_data();
}))
app.use(controller.get('/ajax/chapter_data', function*(){
this.set('Cache-Control', 'no-cache');
var params = querystring.parse(this.req._parsedUrl.query);
var id = params.id;
if(!id){
id = "";
}
this.body = service.get_chapter_content_data(id);
}))
app.listen(3000);
console.log('koa server is started!!');