Skip to content

Commit 5450fb8

Browse files
committed
Merge pull request #2 from Allenice/dev
格式化代码
2 parents 6b5c76e + 4b15481 commit 5450fb8

File tree

5 files changed

+252
-253
lines changed

5 files changed

+252
-253
lines changed

example/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
21
var Server = require("../index.js");
32

43
var server = new Server();
54

65
server.register([
7-
require('./article/index'),
8-
require('./user/index')
6+
require('./article/index'),
7+
require('./user/index')
98
]);
109

1110
server.start(3000);

example/article/index.js

Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,109 @@
11
/*
2-
* 文章列子
3-
* -- 路由规则:https://github.com/aaronblohowiak/routes.js
4-
* -- 数据模板文档:http://mockjs.com/
5-
* */
2+
* 文章列子
3+
* -- 路由规则:https://github.com/aaronblohowiak/routes.js
4+
* -- 数据模板文档:http://mockjs.com/
5+
* */
66

7-
module.exports = function (server) {
7+
module.exports = function (server) {
88

9-
// 获取文章列表
10-
server.get('/article/', {
11-
delay: 200,
12-
data: function(params, query) {
13-
console.log(params);
14-
console.log(query);
9+
// 获取文章列表
10+
server.get('/article/', {
11+
delay: 200,
12+
data: function (params, query) {
13+
console.log(params);
14+
console.log(query);
1515

16-
return {
17-
"status": "ok",
18-
"total_count": 100,
19-
"data|10": [
20-
{
21-
"id|1-10000": 1,
22-
"title": "@TITLE(5, 7)",
23-
"author": "@NAME",
24-
"brief": "中文测试",
25-
"post_time": "@DATETIME('yyyy-MM-dd HH:mm:ss')",
26-
"read_count|0-1000": 100
27-
}
28-
]
29-
}
30-
}
31-
});
16+
return {
17+
"status": "ok",
18+
"total_count": 100,
19+
"data|10": [
20+
{
21+
"id|1-10000": 1,
22+
"title": "@TITLE(5, 7)",
23+
"author": "@NAME",
24+
"brief": "中文测试",
25+
"post_time": "@DATETIME('yyyy-MM-dd HH:mm:ss')",
26+
"read_count|0-1000": 100
27+
}
28+
]
29+
}
30+
}
31+
});
3232

33-
// 获取一篇文章
34-
server.get('/article/:id', {
35-
data: function (params, query) {
36-
return {
37-
"status": "ok",
38-
"data": {
39-
"id": params.id,
40-
"title": "@TITLE(5, 7)",
41-
"author": "@NAME",
42-
"post_time": "@DATETIME('yyyy-MM-dd HH:mm:ss')",
43-
"content": "@PARAGRAPH(2)",
44-
"poster": "@IMAGE('700x350', '#ccc', '#000', 'hello world')",
45-
"read_count|0-1000": 100
46-
}
47-
}
48-
}
49-
});
33+
// 获取一篇文章
34+
server.get('/article/:id', {
35+
data: function (params, query) {
36+
return {
37+
"status": "ok",
38+
"data": {
39+
"id": params.id,
40+
"title": "@TITLE(5, 7)",
41+
"author": "@NAME",
42+
"post_time": "@DATETIME('yyyy-MM-dd HH:mm:ss')",
43+
"content": "@PARAGRAPH(2)",
44+
"poster": "@IMAGE('700x350', '#ccc', '#000', 'hello world')",
45+
"read_count|0-1000": 100
46+
}
47+
}
48+
}
49+
});
5050

51-
// 添加一篇文章
52-
server.post('/article/',{
53-
data: function (params, query) {
54-
return {
55-
"status": "ok",
56-
"data": {
57-
"id|1-10000": 1,
58-
"title": query.title,
59-
"author": query.author,
60-
"post_time": "@NOW"
61-
}
62-
}
63-
}
64-
});
51+
// 添加一篇文章
52+
server.post('/article/', {
53+
data: function (params, query) {
54+
return {
55+
"status": "ok",
56+
"data": {
57+
"id|1-10000": 1,
58+
"title": query.title,
59+
"author": query.author,
60+
"post_time": "@NOW"
61+
}
62+
}
63+
}
64+
});
6565

66-
// 删除一篇文章
67-
server.delete('/article/:id', {
68-
data: function (params, query) {
69-
return {
70-
"status": "ok",
71-
"message": "delete article: " + params.id
72-
}
73-
}
74-
});
66+
// 删除一篇文章
67+
server.delete('/article/:id', {
68+
data: function (params, query) {
69+
return {
70+
"status": "ok",
71+
"message": "delete article: " + params.id
72+
}
73+
}
74+
});
7575

76-
// 更新或添加一篇文章
77-
server.put('/article/:id', {
78-
data: function (params, query) {
79-
return {
80-
"status": "ok",
81-
"data": {
82-
"id|1-10000": 1,
83-
"title": query.title,
84-
"author": query.author,
85-
"content": query.content,
86-
"post_time": "@NOW"
87-
}
88-
}
89-
}
90-
});
91-
92-
// 更新一篇文章
93-
server.patch('/article/:id', {
94-
data: function (params, query) {
95-
return {
96-
"status": "ok",
97-
"data": {
98-
"id|1-10000": 1,
99-
"title": query.title,
100-
"author": query.author,
101-
"content": query.content,
102-
"post_time": "@NOW"
103-
}
104-
}
105-
}
106-
});
76+
// 更新或添加一篇文章
77+
server.put('/article/:id', {
78+
data: function (params, query) {
79+
return {
80+
"status": "ok",
81+
"data": {
82+
"id|1-10000": 1,
83+
"title": query.title,
84+
"author": query.author,
85+
"content": query.content,
86+
"post_time": "@NOW"
87+
}
88+
}
89+
}
90+
});
10791

92+
// 更新一篇文章
93+
server.patch('/article/:id', {
94+
data: function (params, query) {
95+
return {
96+
"status": "ok",
97+
"data": {
98+
"id|1-10000": 1,
99+
"title": query.title,
100+
"author": query.author,
101+
"content": query.content,
102+
"post_time": "@NOW"
103+
}
104+
}
105+
}
106+
});
108107

109108

110109
}

example/user/index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
* */
66

77
module.exports = function (server) {
8-
// 获取用户列表
9-
server.get('/user/', {
10-
delay: 200,
11-
data: function(params, query) {
12-
console.log(params);
13-
console.log(query);
8+
// 获取用户列表
9+
server.get('/user/', {
10+
delay: 200,
11+
data: function (params, query) {
12+
console.log(params);
13+
console.log(query);
1414

15-
return {
16-
"status": "ok",
17-
"total_count": 100,
18-
"data|10": [
19-
{
20-
"id|1-10000": 1,
21-
"user_name": "@NAME",
22-
"gender|1": ['male', 'female']
23-
}
24-
]
25-
}
26-
}
27-
});
15+
return {
16+
"status": "ok",
17+
"total_count": 100,
18+
"data|10": [
19+
{
20+
"id|1-10000": 1,
21+
"user_name": "@NAME",
22+
"gender|1": ['male', 'female']
23+
}
24+
]
25+
}
26+
}
27+
});
2828

2929
}

0 commit comments

Comments
 (0)