q-koa 13.8.60 → 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)
|
|
@@ -700,19 +688,6 @@ class APP {
|
|
|
700
688
|
}
|
|
701
689
|
}
|
|
702
690
|
|
|
703
|
-
async initFile(appName) {
|
|
704
|
-
const dirExist = fsExtra.existsSync(path.resolve(__dirname, './file'))
|
|
705
|
-
if (dirExist) {
|
|
706
|
-
await fsExtra.copy(
|
|
707
|
-
path.resolve(__dirname, './file'),
|
|
708
|
-
path.resolve(__dirname, `${rootDirectory}/${APP_DIR}/${appName}`),
|
|
709
|
-
{
|
|
710
|
-
clobber: false,
|
|
711
|
-
}
|
|
712
|
-
)
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
691
|
async initPlugin(appName) {
|
|
717
692
|
const pluginDir = path.resolve(
|
|
718
693
|
__dirname,
|
|
@@ -779,8 +754,7 @@ class APP {
|
|
|
779
754
|
filename
|
|
780
755
|
))
|
|
781
756
|
const _attributes =
|
|
782
|
-
Object.keys(currentAttributes).length === 0 &&
|
|
783
|
-
defaultModelExist
|
|
757
|
+
Object.keys(currentAttributes).length === 0 && defaultModelExist
|
|
784
758
|
? require(defaultModelPath)
|
|
785
759
|
: currentAttributes
|
|
786
760
|
|
|
@@ -932,16 +906,13 @@ class APP {
|
|
|
932
906
|
_attributes,
|
|
933
907
|
(item) => item.mock && typeof item.mock === 'function'
|
|
934
908
|
)
|
|
935
|
-
mount(
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
Object.keys(mockObj),
|
|
941
|
-
Object.keys(mockObj).map((key) =>
|
|
942
|
-
_.result(mockObj, `${key}.mock`)
|
|
943
|
-
)
|
|
909
|
+
mount('mock', folder, () =>
|
|
910
|
+
_.zipObject(
|
|
911
|
+
Object.keys(mockObj),
|
|
912
|
+
Object.keys(mockObj).map((key) =>
|
|
913
|
+
_.result(mockObj, `${key}.mock`)
|
|
944
914
|
)
|
|
915
|
+
)
|
|
945
916
|
)
|
|
946
917
|
}
|
|
947
918
|
} else if (
|
|
@@ -964,10 +935,7 @@ class APP {
|
|
|
964
935
|
`${filename}`
|
|
965
936
|
))
|
|
966
937
|
// 用户模块缺失的方法/配置由框架内置同名模块补齐(仅合并当前模块,不波及整个 app)
|
|
967
|
-
if (
|
|
968
|
-
fs.existsSync(defaultPath) &&
|
|
969
|
-
_.isPlainObject(userModule)
|
|
970
|
-
) {
|
|
938
|
+
if (fs.existsSync(defaultPath) && _.isPlainObject(userModule)) {
|
|
971
939
|
_.defaultsDeep(userModule, require(defaultPath))
|
|
972
940
|
}
|
|
973
941
|
mount(n, folder, userModule)
|
|
@@ -1013,7 +981,6 @@ class APP {
|
|
|
1013
981
|
// 直接赋值,避免对整个 app 对象做 defaultsDeep 深合并(且保持对象引用不变)
|
|
1014
982
|
this.app[appName].include = include
|
|
1015
983
|
for (const model of modelList) {
|
|
1016
|
-
|
|
1017
984
|
// if (!this.app[appName].include || !this.app[appName].include[model]) {
|
|
1018
985
|
// this.app[appName] = _.defaultsDeep(
|
|
1019
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
|
-
}
|