skybase 0.1.82 → 0.1.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +35 -35
- package/.eslintrc +41 -41
- package/CHANGELOG.md +28 -472
- package/README.md +214 -214
- package/demo/1-simple/README.md +1 -1
- package/demo/1-simple/index.js +7 -7
- package/demo/1-simple/model/api/demo.js +26 -26
- package/demo/1-simple/model/api/frontApiFiles//347/224/250/344/272/216/345/261/225/347/244/272/345/246/202/344/275/225/345/256/232/344/271/211/344/270/200/344/270/252/346/216/245/345/217/243.js +32 -32
- package/demo/1-simple/model//347/224/250/344/272/216/345/261/225/347/244/272/345/246/202/344/275/225/345/256/232/344/271/211/344/270/200/344/270/252/346/216/245/345/217/243.js +29 -29
- package/demo/1-simple/package.json +11 -11
- package/demo/1-simple/router/demo.js +8 -8
- package/demo/1-simple/ws_router/echo.js +9 -9
- package/demo/2-api-register/README.md +1 -1
- package/demo/2-api-register/config/config.default.js +25 -25
- package/demo/2-api-register/config/config.dev.js +15 -15
- package/demo/2-api-register/config/config.prod.js +15 -15
- package/demo/2-api-register/config/config.test.js +15 -15
- package/demo/2-api-register/config/index.js +32 -32
- package/demo/2-api-register/model/api/demo.js +26 -26
- package/demo/2-api-register/model/api/dir/demo.js +27 -27
- package/demo/2-api-register/model/api/redirect.js +30 -30
- package/demo/2-api-register/model/api/use-limit.js +45 -45
- package/demo/2-api-register/package.json +11 -11
- package/demo/2-api-register/router/demo.js +9 -9
- package/demo/2-api-register/router/dir/demo.js +9 -9
- package/demo/2-api-register/router/redirect.js +8 -8
- package/demo/2-api-register/router/use-limit.js +9 -9
- package/demo/3-full-module/README.md +1 -1
- package/demo/3-full-module/config/config.default.js +33 -33
- package/demo/3-full-module/config/config.dev.js +15 -15
- package/demo/3-full-module/config/config.prod.js +15 -15
- package/demo/3-full-module/config/config.test.js +15 -15
- package/demo/3-full-module/config/index.js +32 -32
- package/demo/3-full-module/index.js +36 -36
- package/demo/3-full-module/model/api/demo.js +26 -26
- package/demo/3-full-module/model/api/dir/demo.js +26 -26
- package/demo/3-full-module/model/api/use-rabbitmq.js +26 -26
- package/demo/3-full-module/model/api/use-redis.js +33 -33
- package/demo/3-full-module/package.json +17 -17
- package/demo/3-full-module/rabbit-consumer.js +45 -45
- package/demo/3-full-module/router/demo.js +9 -9
- package/demo/3-full-module/router/dir/demo.js +9 -9
- package/demo/3-full-module/router/use-redis.js +14 -14
- package/demo/4-api-to-file/README.md +8 -8
- package/demo/4-api-to-file/config/config.default.js +8 -8
- package/demo/4-api-to-file/config/index.js +32 -32
- package/demo/4-api-to-file/index.js +6 -6
- package/demo/4-api-to-file/model/api/api.js +142 -142
- package/demo/4-api-to-file/package.json +14 -14
- package/demo/4-api-to-file/router/api.js +37 -37
- package/demo/5-mock-api/README.md +2 -2
- package/demo/5-mock-api/config/config.default.js +8 -8
- package/demo/5-mock-api/config/index.js +32 -32
- package/demo/5-mock-api/index.js +24 -24
- package/demo/5-mock-api/model/api/mock.js +213 -213
- package/demo/5-mock-api/model/mock.js +27 -27
- package/demo/5-mock-api/package.json +15 -15
- package/demo/5-mock-api/router/mock.js +20 -20
- package/demo/6-sql-test/README.md +1 -1
- package/demo/6-sql-test/config/config.default.js +61 -61
- package/demo/6-sql-test/config/config.dev.js +15 -15
- package/demo/6-sql-test/config/config.prod.js +15 -15
- package/demo/6-sql-test/config/config.test.js +15 -15
- package/demo/6-sql-test/config/index.js +32 -32
- package/demo/6-sql-test/index.js +48 -48
- package/demo/6-sql-test/model/api/dir/dir/dir/four.js +18 -18
- package/demo/6-sql-test/model/api/dir/dir/three.js +26 -26
- package/demo/6-sql-test/model/api/dir/two.js +26 -26
- package/demo/6-sql-test/model/api/one.js +18 -18
- package/demo/6-sql-test/package.json +18 -18
- package/demo/6-sql-test/router/test.js +38 -38
- package/demo/6-sql-test/service/test.js +96 -96
- package/demo/7-token/README.md +1 -1
- package/demo/7-token/config/config.default.js +35 -35
- package/demo/7-token/config/config.dev.js +15 -15
- package/demo/7-token/config/config.prod.js +15 -15
- package/demo/7-token/config/config.test.js +15 -15
- package/demo/7-token/config/index.js +32 -32
- package/demo/7-token/model/api/demo.js +43 -43
- package/demo/7-token/package.json +17 -17
- package/demo/8-test/README.md +1 -1
- package/demo/8-test/config/config.default.js +35 -35
- package/demo/8-test/config/config.dev.js +15 -15
- package/demo/8-test/config/config.prod.js +15 -15
- package/demo/8-test/config/config.test.js +15 -15
- package/demo/8-test/config/index.js +32 -32
- package/demo/8-test/index.js +30 -30
- package/demo/8-test/model/api/demo.js +43 -43
- package/demo/8-test/model/api/dir/two.js +26 -26
- package/demo/8-test/model/api/mock.js +157 -157
- package/demo/8-test/model/api/one.js +150 -150
- package/demo/8-test/model/mock.js +35 -35
- package/demo/8-test/package.json +17 -17
- package/demo/8-test/router/demo.js +45 -45
- package/demo/8-test/router/mock.js +20 -20
- package/demo/8-test/router/test.js +43 -43
- package/demo/8-test/service/test.js +35 -35
- package/demo/9-mysql-chart/config/config.dev.js +15 -15
- package/demo/9-mysql-chart/config/config.prod.js +15 -15
- package/demo/9-mysql-chart/config/config.test.js +15 -15
- package/demo/9-mysql-chart/index.js +36 -36
- package/demo/9-mysql-chart/package.json +18 -18
- package/lib/middleware/sky-api-register.js +348 -348
- package/lib/middleware/sky-check-param.js +6 -1
- package/lib/middleware/sky-cors.js +8 -8
- package/lib/middleware/sky-output.js +83 -83
- package/lib/middleware/sky-static-server.js +16 -16
- package/outFiles.js +325 -325
- package/package.json +50 -67
- package/sky-module/create_amqplib.js +69 -69
- package/sky-module/create_ioredis.js +47 -47
- package/sky-module/create_kafka.js +24 -24
- package/skyconfig.js +2 -1
- package/tests/test.js +173 -173
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
__swagger__: {
|
|
3
|
-
name: '测试用例接口',
|
|
4
|
-
description: '测试用例接口'
|
|
5
|
-
},
|
|
6
|
-
'/one': {
|
|
7
|
-
name: 'demo接口1',
|
|
8
|
-
desc: 'demo接口1',
|
|
9
|
-
method: 'get',
|
|
10
|
-
controller: 'test.one',
|
|
11
|
-
param: { },
|
|
12
|
-
'token': false,
|
|
13
|
-
'needSign': false,
|
|
14
|
-
'err_code': {},
|
|
15
|
-
'test': {},
|
|
16
|
-
'front': true
|
|
17
|
-
},
|
|
18
|
-
'/testErrCode': {
|
|
19
|
-
name: '测试errCode',
|
|
20
|
-
desc: '测试errCode',
|
|
21
|
-
method: 'get',
|
|
22
|
-
controller: 'test.testErrCode',
|
|
23
|
-
param: { },
|
|
24
|
-
'token': false,
|
|
25
|
-
'needSign': false,
|
|
26
|
-
'err_code': {},
|
|
27
|
-
'test': {},
|
|
28
|
-
'front': true
|
|
29
|
-
},
|
|
30
|
-
'/testErrCodeArr': {
|
|
31
|
-
name: '测试errCode',
|
|
32
|
-
desc: '测试errCode',
|
|
33
|
-
method: 'get',
|
|
34
|
-
controller: 'test.testErrCodeArr',
|
|
35
|
-
param: { },
|
|
36
|
-
'token': false,
|
|
37
|
-
'needSign': false,
|
|
38
|
-
'err_code': {},
|
|
39
|
-
'test': {},
|
|
40
|
-
'front': true
|
|
41
|
-
},
|
|
42
|
-
'/testErrCodeObj': {
|
|
43
|
-
name: '测试errCode',
|
|
44
|
-
desc: '测试errCode',
|
|
45
|
-
method: 'get',
|
|
46
|
-
controller: 'test.testErrCodeObj',
|
|
47
|
-
param: { },
|
|
48
|
-
'token': false,
|
|
49
|
-
'needSign': false,
|
|
50
|
-
'err_code': {},
|
|
51
|
-
'test': {},
|
|
52
|
-
'front': true
|
|
53
|
-
},
|
|
54
|
-
'/testErrCodeErr': {
|
|
55
|
-
name: '测试errCode',
|
|
56
|
-
desc: '测试errCode',
|
|
57
|
-
method: 'get',
|
|
58
|
-
controller: 'test.testErrCodeErr',
|
|
59
|
-
param: { },
|
|
60
|
-
'token': false,
|
|
61
|
-
'needSign': false,
|
|
62
|
-
'err_code': {},
|
|
63
|
-
'test': {},
|
|
64
|
-
'front': true
|
|
65
|
-
},
|
|
66
|
-
'/testErr': {
|
|
67
|
-
name: '测试异常',
|
|
68
|
-
desc: '测试异常',
|
|
69
|
-
method: 'get',
|
|
70
|
-
controller: 'test.testErr',
|
|
71
|
-
param: { },
|
|
72
|
-
'token': false,
|
|
73
|
-
'needSign': false,
|
|
74
|
-
'err_code': {},
|
|
75
|
-
'test': {},
|
|
76
|
-
'front': true
|
|
77
|
-
},
|
|
78
|
-
'/testNoName': {
|
|
79
|
-
method: 'get',
|
|
80
|
-
controller: 'test.testErrCodeObj',
|
|
81
|
-
param: { },
|
|
82
|
-
'token': false,
|
|
83
|
-
'needSign': false,
|
|
84
|
-
'err_code': {},
|
|
85
|
-
'test': {},
|
|
86
|
-
'front': true
|
|
87
|
-
},
|
|
88
|
-
'/testErr_Code_Obj': {
|
|
89
|
-
name: '测试errCode',
|
|
90
|
-
desc: '测试errCode',
|
|
91
|
-
method: 'get',
|
|
92
|
-
controller: 'test.testErrCodeObj',
|
|
93
|
-
param: { },
|
|
94
|
-
'token': false,
|
|
95
|
-
'needSign': false,
|
|
96
|
-
'err_code': {},
|
|
97
|
-
'test': {},
|
|
98
|
-
'front': true
|
|
99
|
-
},
|
|
100
|
-
'/noController': {
|
|
101
|
-
name: '',
|
|
102
|
-
desc: '',
|
|
103
|
-
method: 'get',
|
|
104
|
-
controller: 'test.noController',
|
|
105
|
-
param: { },
|
|
106
|
-
'token': false,
|
|
107
|
-
'needSign': false,
|
|
108
|
-
'err_code': {},
|
|
109
|
-
'test': {},
|
|
110
|
-
'front': true
|
|
111
|
-
},
|
|
112
|
-
'/noFile': {
|
|
113
|
-
name: '',
|
|
114
|
-
desc: '',
|
|
115
|
-
method: 'get',
|
|
116
|
-
controller: 'asdf.noFile',
|
|
117
|
-
param: { },
|
|
118
|
-
'token': false,
|
|
119
|
-
'needSign': false,
|
|
120
|
-
'err_code': {},
|
|
121
|
-
'test': {},
|
|
122
|
-
'front': true
|
|
123
|
-
},
|
|
124
|
-
'/mock/image': {
|
|
125
|
-
name: '',
|
|
126
|
-
desc: '',
|
|
127
|
-
method: 'get',
|
|
128
|
-
feqLimit: 1000,
|
|
129
|
-
controller: 'test.two',
|
|
130
|
-
param: { },
|
|
131
|
-
'token': false,
|
|
132
|
-
'needSign': false,
|
|
133
|
-
'err_code': {},
|
|
134
|
-
'test': {},
|
|
135
|
-
'front': true
|
|
136
|
-
},
|
|
137
|
-
'/testReturn': {
|
|
138
|
-
name: '',
|
|
139
|
-
desc: '',
|
|
140
|
-
method: 'get',
|
|
141
|
-
feqLimit: 1000,
|
|
142
|
-
controller: 'test.testReturn',
|
|
143
|
-
param: { },
|
|
144
|
-
'token': false,
|
|
145
|
-
'needSign': false,
|
|
146
|
-
'err_code': {},
|
|
147
|
-
'test': {},
|
|
148
|
-
'front': true
|
|
149
|
-
}
|
|
150
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
__swagger__: {
|
|
3
|
+
name: '测试用例接口',
|
|
4
|
+
description: '测试用例接口'
|
|
5
|
+
},
|
|
6
|
+
'/one': {
|
|
7
|
+
name: 'demo接口1',
|
|
8
|
+
desc: 'demo接口1',
|
|
9
|
+
method: 'get',
|
|
10
|
+
controller: 'test.one',
|
|
11
|
+
param: { },
|
|
12
|
+
'token': false,
|
|
13
|
+
'needSign': false,
|
|
14
|
+
'err_code': {},
|
|
15
|
+
'test': {},
|
|
16
|
+
'front': true
|
|
17
|
+
},
|
|
18
|
+
'/testErrCode': {
|
|
19
|
+
name: '测试errCode',
|
|
20
|
+
desc: '测试errCode',
|
|
21
|
+
method: 'get',
|
|
22
|
+
controller: 'test.testErrCode',
|
|
23
|
+
param: { },
|
|
24
|
+
'token': false,
|
|
25
|
+
'needSign': false,
|
|
26
|
+
'err_code': {},
|
|
27
|
+
'test': {},
|
|
28
|
+
'front': true
|
|
29
|
+
},
|
|
30
|
+
'/testErrCodeArr': {
|
|
31
|
+
name: '测试errCode',
|
|
32
|
+
desc: '测试errCode',
|
|
33
|
+
method: 'get',
|
|
34
|
+
controller: 'test.testErrCodeArr',
|
|
35
|
+
param: { },
|
|
36
|
+
'token': false,
|
|
37
|
+
'needSign': false,
|
|
38
|
+
'err_code': {},
|
|
39
|
+
'test': {},
|
|
40
|
+
'front': true
|
|
41
|
+
},
|
|
42
|
+
'/testErrCodeObj': {
|
|
43
|
+
name: '测试errCode',
|
|
44
|
+
desc: '测试errCode',
|
|
45
|
+
method: 'get',
|
|
46
|
+
controller: 'test.testErrCodeObj',
|
|
47
|
+
param: { },
|
|
48
|
+
'token': false,
|
|
49
|
+
'needSign': false,
|
|
50
|
+
'err_code': {},
|
|
51
|
+
'test': {},
|
|
52
|
+
'front': true
|
|
53
|
+
},
|
|
54
|
+
'/testErrCodeErr': {
|
|
55
|
+
name: '测试errCode',
|
|
56
|
+
desc: '测试errCode',
|
|
57
|
+
method: 'get',
|
|
58
|
+
controller: 'test.testErrCodeErr',
|
|
59
|
+
param: { },
|
|
60
|
+
'token': false,
|
|
61
|
+
'needSign': false,
|
|
62
|
+
'err_code': {},
|
|
63
|
+
'test': {},
|
|
64
|
+
'front': true
|
|
65
|
+
},
|
|
66
|
+
'/testErr': {
|
|
67
|
+
name: '测试异常',
|
|
68
|
+
desc: '测试异常',
|
|
69
|
+
method: 'get',
|
|
70
|
+
controller: 'test.testErr',
|
|
71
|
+
param: { },
|
|
72
|
+
'token': false,
|
|
73
|
+
'needSign': false,
|
|
74
|
+
'err_code': {},
|
|
75
|
+
'test': {},
|
|
76
|
+
'front': true
|
|
77
|
+
},
|
|
78
|
+
'/testNoName': {
|
|
79
|
+
method: 'get',
|
|
80
|
+
controller: 'test.testErrCodeObj',
|
|
81
|
+
param: { },
|
|
82
|
+
'token': false,
|
|
83
|
+
'needSign': false,
|
|
84
|
+
'err_code': {},
|
|
85
|
+
'test': {},
|
|
86
|
+
'front': true
|
|
87
|
+
},
|
|
88
|
+
'/testErr_Code_Obj': {
|
|
89
|
+
name: '测试errCode',
|
|
90
|
+
desc: '测试errCode',
|
|
91
|
+
method: 'get',
|
|
92
|
+
controller: 'test.testErrCodeObj',
|
|
93
|
+
param: { },
|
|
94
|
+
'token': false,
|
|
95
|
+
'needSign': false,
|
|
96
|
+
'err_code': {},
|
|
97
|
+
'test': {},
|
|
98
|
+
'front': true
|
|
99
|
+
},
|
|
100
|
+
'/noController': {
|
|
101
|
+
name: '',
|
|
102
|
+
desc: '',
|
|
103
|
+
method: 'get',
|
|
104
|
+
controller: 'test.noController',
|
|
105
|
+
param: { },
|
|
106
|
+
'token': false,
|
|
107
|
+
'needSign': false,
|
|
108
|
+
'err_code': {},
|
|
109
|
+
'test': {},
|
|
110
|
+
'front': true
|
|
111
|
+
},
|
|
112
|
+
'/noFile': {
|
|
113
|
+
name: '',
|
|
114
|
+
desc: '',
|
|
115
|
+
method: 'get',
|
|
116
|
+
controller: 'asdf.noFile',
|
|
117
|
+
param: { },
|
|
118
|
+
'token': false,
|
|
119
|
+
'needSign': false,
|
|
120
|
+
'err_code': {},
|
|
121
|
+
'test': {},
|
|
122
|
+
'front': true
|
|
123
|
+
},
|
|
124
|
+
'/mock/image': {
|
|
125
|
+
name: '',
|
|
126
|
+
desc: '',
|
|
127
|
+
method: 'get',
|
|
128
|
+
feqLimit: 1000,
|
|
129
|
+
controller: 'test.two',
|
|
130
|
+
param: { },
|
|
131
|
+
'token': false,
|
|
132
|
+
'needSign': false,
|
|
133
|
+
'err_code': {},
|
|
134
|
+
'test': {},
|
|
135
|
+
'front': true
|
|
136
|
+
},
|
|
137
|
+
'/testReturn': {
|
|
138
|
+
name: '',
|
|
139
|
+
desc: '',
|
|
140
|
+
method: 'get',
|
|
141
|
+
feqLimit: 1000,
|
|
142
|
+
controller: 'test.testReturn',
|
|
143
|
+
param: { },
|
|
144
|
+
'token': false,
|
|
145
|
+
'needSign': false,
|
|
146
|
+
'err_code': {},
|
|
147
|
+
'test': {},
|
|
148
|
+
'front': true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @author: cuiguanghao
|
|
5
|
-
* @date: 2019年06月18日11:31:06
|
|
6
|
-
* @name: mock.js
|
|
7
|
-
* @description: 闭包函数返回mock数据 已router的方式
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/* global $ */
|
|
11
|
-
|
|
12
|
-
const Mock = require('mockjs')
|
|
13
|
-
Mock.Random.extend($.Mock)
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
noMock,
|
|
17
|
-
mockRouter,
|
|
18
|
-
mock
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function noMock () {
|
|
22
|
-
return function (ctx) {
|
|
23
|
-
ctx.ok('controller未定义 & mock未定义')
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function mockRouter (mockModels) {
|
|
28
|
-
return function (ctx) {
|
|
29
|
-
ctx.ok(Mock.mock(mockModels))
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function mock (mockModels) {
|
|
34
|
-
return Mock.mock(mockModels)
|
|
35
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @author: cuiguanghao
|
|
5
|
+
* @date: 2019年06月18日11:31:06
|
|
6
|
+
* @name: mock.js
|
|
7
|
+
* @description: 闭包函数返回mock数据 已router的方式
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* global $ */
|
|
11
|
+
|
|
12
|
+
const Mock = require('mockjs')
|
|
13
|
+
Mock.Random.extend($.Mock)
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
noMock,
|
|
17
|
+
mockRouter,
|
|
18
|
+
mock
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function noMock () {
|
|
22
|
+
return function (ctx) {
|
|
23
|
+
ctx.ok('controller未定义 & mock未定义')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function mockRouter (mockModels) {
|
|
28
|
+
return function (ctx) {
|
|
29
|
+
ctx.ok(Mock.mock(mockModels))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mock (mockModels) {
|
|
34
|
+
return Mock.mock(mockModels)
|
|
35
|
+
}
|
package/demo/8-test/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "8-test",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "含所有模块的应用",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"author": "",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"j2sql": "^1.9.21",
|
|
13
|
-
"amqplib": "^0.5.3",
|
|
14
|
-
"ioredis": "^4.9.5",
|
|
15
|
-
"meeko": "^1.7.50"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "8-test",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "含所有模块的应用",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"j2sql": "^1.9.21",
|
|
13
|
+
"amqplib": "^0.5.3",
|
|
14
|
+
"ioredis": "^4.9.5",
|
|
15
|
+
"meeko": "^1.7.50"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
/* global $ redis */
|
|
3
|
-
|
|
4
|
-
const Config = require('../../../config.js')
|
|
5
|
-
const Crypto = require('crypto')
|
|
6
|
-
const tokenSaveTime = 3600 * 5 // redis 数据缓存保留时间 单位:秒
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
async login (ctx) {
|
|
10
|
-
const { account, password } = ctx.checkedData.data
|
|
11
|
-
let token = await setToken({ id: 1, account, password })
|
|
12
|
-
ctx.throwCode(200, '成功', { token })
|
|
13
|
-
},
|
|
14
|
-
async home (ctx) {
|
|
15
|
-
ctx.throwCode(200, '成功', ctx.checkedToken)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 创建token 以id 并且设定用户数据
|
|
20
|
-
async function setToken (obj) { // obj - 存放对象
|
|
21
|
-
try {
|
|
22
|
-
let s = obj.id + ' ' + +new Date()
|
|
1
|
+
|
|
2
|
+
/* global $ redis */
|
|
3
|
+
|
|
4
|
+
const Config = require('../../../config.js')
|
|
5
|
+
const Crypto = require('crypto')
|
|
6
|
+
const tokenSaveTime = 3600 * 5 // redis 数据缓存保留时间 单位:秒
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
async login (ctx) {
|
|
10
|
+
const { account, password } = ctx.checkedData.data
|
|
11
|
+
let token = await setToken({ id: 1, account, password })
|
|
12
|
+
ctx.throwCode(200, '成功', { token })
|
|
13
|
+
},
|
|
14
|
+
async home (ctx) {
|
|
15
|
+
ctx.throwCode(200, '成功', ctx.checkedToken)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 创建token 以id 并且设定用户数据
|
|
20
|
+
async function setToken (obj) { // obj - 存放对象
|
|
21
|
+
try {
|
|
22
|
+
let s = obj.id + ' ' + +new Date()
|
|
23
23
|
let token = Crypto.createHmac('sha256', s.slice(0, 5)).update(s)
|
|
24
|
-
.digest('base64')
|
|
25
|
-
let keyStr = Config.tokenName + ':userlogin:' + token
|
|
26
|
-
if (await redis.setex(keyStr, tokenSaveTime, JSON.stringify(obj)) === 'OK') { // 保存2个小时
|
|
27
|
-
// 删除原先的登录凭证
|
|
28
|
-
await delOldToken(obj.id)
|
|
29
|
-
// 设定新的登录凭证
|
|
30
|
-
await redis.set(Config.tokenName + ':id:' + obj.id, token)
|
|
31
|
-
return token
|
|
32
|
-
}
|
|
33
|
-
return -1
|
|
34
|
-
} catch (e) {
|
|
35
|
-
$.err(e)
|
|
36
|
-
return -1
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 删除原先的登录凭证
|
|
41
|
-
async function delOldToken (id) {
|
|
42
|
-
let ot = await redis.get(Config.tokenName + ':id:' + id)
|
|
43
|
-
if (ot && ot.length > 13) {
|
|
44
|
-
await redis.del(Config.tokenName + ':userlogin:' + ot)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
24
|
+
.digest('base64')
|
|
25
|
+
let keyStr = Config.tokenName + ':userlogin:' + token
|
|
26
|
+
if (await redis.setex(keyStr, tokenSaveTime, JSON.stringify(obj)) === 'OK') { // 保存2个小时
|
|
27
|
+
// 删除原先的登录凭证
|
|
28
|
+
await delOldToken(obj.id)
|
|
29
|
+
// 设定新的登录凭证
|
|
30
|
+
await redis.set(Config.tokenName + ':id:' + obj.id, token)
|
|
31
|
+
return token
|
|
32
|
+
}
|
|
33
|
+
return -1
|
|
34
|
+
} catch (e) {
|
|
35
|
+
$.err(e)
|
|
36
|
+
return -1
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 删除原先的登录凭证
|
|
41
|
+
async function delOldToken (id) {
|
|
42
|
+
let ot = await redis.get(Config.tokenName + ':id:' + id)
|
|
43
|
+
if (ot && ot.length > 13) {
|
|
44
|
+
await redis.del(Config.tokenName + ':userlogin:' + ot)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
const Mock = require('mockjs')
|
|
3
|
-
|
|
4
|
-
/* global $ */
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
async haveController (ctx) {
|
|
8
|
-
ctx.ok({})
|
|
9
|
-
},
|
|
10
|
-
async image (ctx) {
|
|
11
|
-
const { width, heigth, count, type } = ctx.checkedData.data
|
|
12
|
-
let data = { list: [] }
|
|
13
|
-
const Random = Mock.Random
|
|
14
|
-
for (let i = 0; i < count; i++) {
|
|
15
|
-
data.list.push(Random.image(`${width}x${heigth}`, Random.color(), Random.color(), type, `${width}x${heigth}`))
|
|
16
|
-
}
|
|
17
|
-
$.log(data)
|
|
18
|
-
ctx.ok(data)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
|
|
2
|
+
const Mock = require('mockjs')
|
|
3
|
+
|
|
4
|
+
/* global $ */
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
async haveController (ctx) {
|
|
8
|
+
ctx.ok({})
|
|
9
|
+
},
|
|
10
|
+
async image (ctx) {
|
|
11
|
+
const { width, heigth, count, type } = ctx.checkedData.data
|
|
12
|
+
let data = { list: [] }
|
|
13
|
+
const Random = Mock.Random
|
|
14
|
+
for (let i = 0; i < count; i++) {
|
|
15
|
+
data.list.push(Random.image(`${width}x${heigth}`, Random.color(), Random.color(), type, `${width}x${heigth}`))
|
|
16
|
+
}
|
|
17
|
+
$.log(data)
|
|
18
|
+
ctx.ok(data)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
const testService = require('../service/test.js')
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
async one (ctx) {
|
|
6
|
-
const r = await testService.one(ctx.checkedData.data)
|
|
7
|
-
if (r && r.code === 0) {
|
|
8
|
-
ctx.throwCode(200, '成功', r.data)
|
|
9
|
-
} else {
|
|
10
|
-
ctx.throwCode(r.code, r.msg)
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
async two (ctx) {
|
|
14
|
-
const r = await testService.two(ctx.checkedData.data)
|
|
15
|
-
if (r && r.code === 0) {
|
|
16
|
-
ctx.throwCode(200, '成功', r.data)
|
|
17
|
-
} else {
|
|
18
|
-
ctx.throwCode(r.code, r.msg)
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
async testErrCode (ctx) {
|
|
22
|
-
ctx.throwCode(null, '测试')
|
|
23
|
-
},
|
|
24
|
-
async testErrCodeArr (ctx) {
|
|
25
|
-
ctx.throwCode([200, 'test', {}], '测试')
|
|
26
|
-
},
|
|
27
|
-
async testErrCodeObj (ctx) {
|
|
28
|
-
ctx.throwCode({ constructor: Object }, '测试')
|
|
29
|
-
},
|
|
30
|
-
async testErrCodeErr (ctx) {
|
|
31
|
-
ctx.throwCode({ constructor: {} }, '测试')
|
|
32
|
-
},
|
|
33
|
-
async testErr (ctx) {
|
|
34
|
-
let t = 0
|
|
35
|
-
try {
|
|
36
|
-
t = 123 / t
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error(error.stack)
|
|
39
|
-
}
|
|
40
|
-
console.log(t)
|
|
41
|
-
ctx.throwCode(500, '测试')
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
|
|
2
|
+
const testService = require('../service/test.js')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
async one (ctx) {
|
|
6
|
+
const r = await testService.one(ctx.checkedData.data)
|
|
7
|
+
if (r && r.code === 0) {
|
|
8
|
+
ctx.throwCode(200, '成功', r.data)
|
|
9
|
+
} else {
|
|
10
|
+
ctx.throwCode(r.code, r.msg)
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
async two (ctx) {
|
|
14
|
+
const r = await testService.two(ctx.checkedData.data)
|
|
15
|
+
if (r && r.code === 0) {
|
|
16
|
+
ctx.throwCode(200, '成功', r.data)
|
|
17
|
+
} else {
|
|
18
|
+
ctx.throwCode(r.code, r.msg)
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
async testErrCode (ctx) {
|
|
22
|
+
ctx.throwCode(null, '测试')
|
|
23
|
+
},
|
|
24
|
+
async testErrCodeArr (ctx) {
|
|
25
|
+
ctx.throwCode([200, 'test', {}], '测试')
|
|
26
|
+
},
|
|
27
|
+
async testErrCodeObj (ctx) {
|
|
28
|
+
ctx.throwCode({ constructor: Object }, '测试')
|
|
29
|
+
},
|
|
30
|
+
async testErrCodeErr (ctx) {
|
|
31
|
+
ctx.throwCode({ constructor: {} }, '测试')
|
|
32
|
+
},
|
|
33
|
+
async testErr (ctx) {
|
|
34
|
+
let t = 0
|
|
35
|
+
try {
|
|
36
|
+
t = 123 / t
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(error.stack)
|
|
39
|
+
}
|
|
40
|
+
console.log(t)
|
|
41
|
+
ctx.throwCode(500, '测试')
|
|
42
|
+
}
|
|
43
|
+
}
|