q-koa 12.9.2 → 12.9.3
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 +41 -0
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -772,6 +772,29 @@ class APP {
|
|
|
772
772
|
})
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
|
+
const start = moment().valueOf()
|
|
776
|
+
for (const fn of ['service', 'controller']) {
|
|
777
|
+
const cloneTarget = this.app[appName][fn]
|
|
778
|
+
|
|
779
|
+
this.app[appName][fn] = Object.keys(cloneTarget).reduce((a, b) => {
|
|
780
|
+
const modelService = cloneTarget[b]
|
|
781
|
+
const newB = Object.keys(modelService).reduce((_a, _b) => {
|
|
782
|
+
const bindFn = modelService[_b].bind(this.app[appName])
|
|
783
|
+
return {
|
|
784
|
+
..._a,
|
|
785
|
+
[_b]: bindFn,
|
|
786
|
+
}
|
|
787
|
+
}, {})
|
|
788
|
+
return {
|
|
789
|
+
...a,
|
|
790
|
+
[b]: newB,
|
|
791
|
+
}
|
|
792
|
+
}, {})
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (is_dev) {
|
|
796
|
+
console.log(moment().valueOf() - start)
|
|
797
|
+
}
|
|
775
798
|
}
|
|
776
799
|
|
|
777
800
|
initModel(appName) {
|
|
@@ -936,6 +959,24 @@ class APP {
|
|
|
936
959
|
]
|
|
937
960
|
for (let i = 0; i < hooksList.length; i++) {
|
|
938
961
|
if (_.get(app, `${appName}.${hooksList[i]}.${controller}.${fn}`)) {
|
|
962
|
+
if (hooksList[i] === 'controller') {
|
|
963
|
+
process.once('unhandledRejection', (reason, promise) => {
|
|
964
|
+
if (
|
|
965
|
+
this.app &&
|
|
966
|
+
this.app[appName] &&
|
|
967
|
+
this.app[appName].model &&
|
|
968
|
+
this.app[appName].model.log
|
|
969
|
+
) {
|
|
970
|
+
this.app[appName].model.log.create({
|
|
971
|
+
url: ctx.request.href,
|
|
972
|
+
body: ctx.request.body,
|
|
973
|
+
message: 'promise unhandledRejection',
|
|
974
|
+
content: reason.stack,
|
|
975
|
+
header: ctx.request.header,
|
|
976
|
+
})
|
|
977
|
+
}
|
|
978
|
+
})
|
|
979
|
+
}
|
|
939
980
|
await app[appName][hooksList[i]][controller][fn](ctx)
|
|
940
981
|
}
|
|
941
982
|
}
|