q-koa 13.8.59 → 13.8.61
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/core/app.js
CHANGED
|
@@ -465,11 +465,7 @@ class APP {
|
|
|
465
465
|
let sharedRedisClient = null
|
|
466
466
|
let sharedSubscriber = null
|
|
467
467
|
let redisError = null
|
|
468
|
-
if (
|
|
469
|
-
this.config.redis &&
|
|
470
|
-
this.config.redis.host &&
|
|
471
|
-
this.config.redis.port
|
|
472
|
-
) {
|
|
468
|
+
if (this.config.redis && this.config.redis.host && this.config.redis.port) {
|
|
473
469
|
try {
|
|
474
470
|
sharedRedisClient = redis.createClient({
|
|
475
471
|
socket: {
|
|
@@ -662,14 +658,6 @@ class APP {
|
|
|
662
658
|
}
|
|
663
659
|
}
|
|
664
660
|
|
|
665
|
-
const initFileConfig = _.get(
|
|
666
|
-
this.app[appName],
|
|
667
|
-
'appConfig.initFile',
|
|
668
|
-
false
|
|
669
|
-
)
|
|
670
|
-
if (initFileConfig) {
|
|
671
|
-
await this.initFile(appName)
|
|
672
|
-
}
|
|
673
661
|
await this.initPlugin(appName)
|
|
674
662
|
|
|
675
663
|
const initEvent = _.get(this.app[appName], 'appConfig.initEvent', false)
|
|
@@ -684,7 +672,8 @@ class APP {
|
|
|
684
672
|
|
|
685
673
|
this.app[appName].cache = new LRUCache({
|
|
686
674
|
max: cacheConfig.max,
|
|
687
|
-
ttl
|
|
675
|
+
// 兼容业务方两种写法:lru-cache v11 的 ttl 或旧版 maxAge
|
|
676
|
+
ttl: cacheConfig.ttl || cacheConfig.maxAge,
|
|
688
677
|
})
|
|
689
678
|
|
|
690
679
|
await this.initModel(appName)
|
|
@@ -699,19 +688,6 @@ class APP {
|
|
|
699
688
|
}
|
|
700
689
|
}
|
|
701
690
|
|
|
702
|
-
async initFile(appName) {
|
|
703
|
-
const dirExist = fsExtra.existsSync(path.resolve(__dirname, './file'))
|
|
704
|
-
if (dirExist) {
|
|
705
|
-
await fsExtra.copy(
|
|
706
|
-
path.resolve(__dirname, './file'),
|
|
707
|
-
path.resolve(__dirname, `${rootDirectory}/${APP_DIR}/${appName}`),
|
|
708
|
-
{
|
|
709
|
-
clobber: false,
|
|
710
|
-
}
|
|
711
|
-
)
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
691
|
async initPlugin(appName) {
|
|
716
692
|
const pluginDir = path.resolve(
|
|
717
693
|
__dirname,
|
|
@@ -778,8 +754,7 @@ class APP {
|
|
|
778
754
|
filename
|
|
779
755
|
))
|
|
780
756
|
const _attributes =
|
|
781
|
-
Object.keys(currentAttributes).length === 0 &&
|
|
782
|
-
defaultModelExist
|
|
757
|
+
Object.keys(currentAttributes).length === 0 && defaultModelExist
|
|
783
758
|
? require(defaultModelPath)
|
|
784
759
|
: currentAttributes
|
|
785
760
|
|
|
@@ -931,16 +906,13 @@ class APP {
|
|
|
931
906
|
_attributes,
|
|
932
907
|
(item) => item.mock && typeof item.mock === 'function'
|
|
933
908
|
)
|
|
934
|
-
mount(
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
Object.keys(mockObj),
|
|
940
|
-
Object.keys(mockObj).map((key) =>
|
|
941
|
-
_.result(mockObj, `${key}.mock`)
|
|
942
|
-
)
|
|
909
|
+
mount('mock', folder, () =>
|
|
910
|
+
_.zipObject(
|
|
911
|
+
Object.keys(mockObj),
|
|
912
|
+
Object.keys(mockObj).map((key) =>
|
|
913
|
+
_.result(mockObj, `${key}.mock`)
|
|
943
914
|
)
|
|
915
|
+
)
|
|
944
916
|
)
|
|
945
917
|
}
|
|
946
918
|
} else if (
|
|
@@ -963,10 +935,7 @@ class APP {
|
|
|
963
935
|
`${filename}`
|
|
964
936
|
))
|
|
965
937
|
// 用户模块缺失的方法/配置由框架内置同名模块补齐(仅合并当前模块,不波及整个 app)
|
|
966
|
-
if (
|
|
967
|
-
fs.existsSync(defaultPath) &&
|
|
968
|
-
_.isPlainObject(userModule)
|
|
969
|
-
) {
|
|
938
|
+
if (fs.existsSync(defaultPath) && _.isPlainObject(userModule)) {
|
|
970
939
|
_.defaultsDeep(userModule, require(defaultPath))
|
|
971
940
|
}
|
|
972
941
|
mount(n, folder, userModule)
|
|
@@ -1012,7 +981,6 @@ class APP {
|
|
|
1012
981
|
// 直接赋值,避免对整个 app 对象做 defaultsDeep 深合并(且保持对象引用不变)
|
|
1013
982
|
this.app[appName].include = include
|
|
1014
983
|
for (const model of modelList) {
|
|
1015
|
-
|
|
1016
984
|
// if (!this.app[appName].include || !this.app[appName].include[model]) {
|
|
1017
985
|
// this.app[appName] = _.defaultsDeep(
|
|
1018
986
|
// {
|
|
@@ -2439,7 +2439,6 @@ exports.union_checkPay = async (ctx) => {
|
|
|
2439
2439
|
const payResult = await allinpay.checkOrder(out_trade_no)
|
|
2440
2440
|
|
|
2441
2441
|
if (payResult) {
|
|
2442
|
-
console.log(payResult)
|
|
2443
2442
|
if (payResult.trxstatus === '0000' && payResult.trxcode === 'VSP501') {
|
|
2444
2443
|
const order_price = Number(payResult.trxamt) / 100
|
|
2445
2444
|
|
package/package.json
CHANGED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
const axios = require('axios')
|
|
2
|
-
const APP = require('q-koa')
|
|
3
|
-
const APP_CONFIG = require('../../config')
|
|
4
|
-
const config = require('./config')
|
|
5
|
-
|
|
6
|
-
const modelName = __dirname.split('/').reverse()[0]
|
|
7
|
-
const service = axios.create({
|
|
8
|
-
baseURL: `http://localhost:${APP_CONFIG.port}/${modelName}`,
|
|
9
|
-
})
|
|
10
|
-
service.interceptors.request.use((config) => {
|
|
11
|
-
config.headers['Client-Type'] = 2
|
|
12
|
-
return config
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
service.interceptors.response.use(
|
|
16
|
-
(response) => response.data,
|
|
17
|
-
(error) => Promise.reject(error)
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
const sleep = (time) =>
|
|
21
|
-
new Promise((resolve) => setTimeout(resolve, time * 1000))
|
|
22
|
-
|
|
23
|
-
describe(`${config.name}/${modelName}`, () => {
|
|
24
|
-
beforeAll(async () => {
|
|
25
|
-
try {
|
|
26
|
-
await axios.post('/')
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.log('正在启动服务器')
|
|
29
|
-
const app = new APP(APP_CONFIG)
|
|
30
|
-
await app.start()
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('错误登录', async () => {
|
|
35
|
-
const res = await service.post('login', {
|
|
36
|
-
name: 'chenlin1',
|
|
37
|
-
password: 'sugar23',
|
|
38
|
-
})
|
|
39
|
-
expect(res.code).toBe(500)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test('正确登录', async () => {
|
|
43
|
-
const res = await service.post('login', {
|
|
44
|
-
name: 'chenlin',
|
|
45
|
-
password: 'sugar23',
|
|
46
|
-
})
|
|
47
|
-
expect(res.code).toBe(200)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('获取token', async () => {
|
|
51
|
-
const {
|
|
52
|
-
data: { token },
|
|
53
|
-
} = await service.post('login', {
|
|
54
|
-
name: 'chenlin',
|
|
55
|
-
password: 'sugar23',
|
|
56
|
-
})
|
|
57
|
-
expect(Boolean(token)).toBe(true)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
test('没有token信息', async () => {
|
|
61
|
-
const res = await service.post('getInfo', {})
|
|
62
|
-
expect(res.code).toBe(401)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('获取用户信息', async () => {
|
|
66
|
-
const {
|
|
67
|
-
data: { token },
|
|
68
|
-
} = await service.post('login', {
|
|
69
|
-
name: 'chenlin',
|
|
70
|
-
password: 'sugar23',
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const res = await service.post(
|
|
74
|
-
'getInfo',
|
|
75
|
-
{},
|
|
76
|
-
{
|
|
77
|
-
headers: {
|
|
78
|
-
'Client-Type': 2,
|
|
79
|
-
'X-Token': token,
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
expect(res.code).toBe(200)
|
|
85
|
-
})
|
|
86
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const { getObject } = require('../utils')
|
|
2
|
-
|
|
3
|
-
module.exports = class Config {
|
|
4
|
-
constructor(app) {
|
|
5
|
-
this.app = app
|
|
6
|
-
this.configList = []
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async init() {
|
|
10
|
-
if (this.app.cache && this.app.cache.get('configList')) {
|
|
11
|
-
this.configList = this.app.cache.get('configList')
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
const configList = await this.app.model.setting.findAll({
|
|
15
|
-
where: {
|
|
16
|
-
type: {
|
|
17
|
-
excludes: ['textarea', 'rich-text'],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
this.app.cache && this.app.cache.set('configList', configList)
|
|
22
|
-
this.configList = configList
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async getObject(type) {
|
|
26
|
-
if (this.app.cache && this.app.cache.get(type))
|
|
27
|
-
return this.app.cache.get(type)
|
|
28
|
-
await this.init()
|
|
29
|
-
const result = getObject(this.configList)(type)
|
|
30
|
-
if (!result) throw new Error('没有这个type')
|
|
31
|
-
this.app.cache && this.app.cache.set(type, result)
|
|
32
|
-
return result
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
update() {
|
|
36
|
-
this.app.cache && this.app.cache.set('configList', null)
|
|
37
|
-
}
|
|
38
|
-
}
|