q-koa 8.0.4 → 8.0.5
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 +26 -13
- package/package.json +2 -1
package/core/app.js
CHANGED
|
@@ -70,7 +70,16 @@ class APP {
|
|
|
70
70
|
constructor(_config) {
|
|
71
71
|
const config = _.defaultsDeep(_config, defaultConfig)
|
|
72
72
|
const { port } = config
|
|
73
|
-
this.config =
|
|
73
|
+
this.config = {
|
|
74
|
+
...config,
|
|
75
|
+
includes: config.includes.map((item) => {
|
|
76
|
+
return typeof item === 'string'
|
|
77
|
+
? {
|
|
78
|
+
item,
|
|
79
|
+
}
|
|
80
|
+
: item
|
|
81
|
+
}),
|
|
82
|
+
}
|
|
74
83
|
this.port = port
|
|
75
84
|
this.app = new Koa()
|
|
76
85
|
this.server = null
|
|
@@ -244,11 +253,12 @@ class APP {
|
|
|
244
253
|
// });
|
|
245
254
|
|
|
246
255
|
starter.on('loadAll', async () => {
|
|
247
|
-
const
|
|
256
|
+
const routerName = this.config.includes[0].routerName
|
|
257
|
+
const appName = this.config.includes[0].dirName
|
|
248
258
|
this.server = this.app.listen(this.port, () => {
|
|
249
259
|
console.log(`server is running at http://localhost:${this.port}`)
|
|
250
260
|
console.log(
|
|
251
|
-
`first app is http://localhost:3001/${
|
|
261
|
+
`first app is http://localhost:3001/${routerName}/setting/findOne`
|
|
252
262
|
)
|
|
253
263
|
})
|
|
254
264
|
|
|
@@ -295,20 +305,17 @@ class APP {
|
|
|
295
305
|
}
|
|
296
306
|
|
|
297
307
|
async initApp() {
|
|
298
|
-
|
|
299
|
-
path.resolve(__dirname, `${rootDirectory}/${APP_DIR}`)
|
|
300
|
-
)
|
|
301
|
-
dirList = dirList.filter((item) => this.config.includes.includes(item))
|
|
302
|
-
|
|
308
|
+
if (this.config.includes.length === 0) throw new Error('请填入项目')
|
|
303
309
|
let dbFlag = false
|
|
304
|
-
for (let i = 0; i <
|
|
305
|
-
const
|
|
310
|
+
for (let i = 0; i < this.config.includes.length; i++) {
|
|
311
|
+
const routerName = this.config.includes[i].routerName
|
|
312
|
+
const appName = this.config.includes[i].dirName
|
|
306
313
|
|
|
307
314
|
console.log(
|
|
308
315
|
chalk.green(`==================== 启动 ${appName} ====================`)
|
|
309
316
|
)
|
|
310
317
|
const routerConfig = {
|
|
311
|
-
prefix: `/${
|
|
318
|
+
prefix: `/${routerName}`,
|
|
312
319
|
}
|
|
313
320
|
const router = new Router(routerConfig)
|
|
314
321
|
Serve(
|
|
@@ -784,7 +791,10 @@ class APP {
|
|
|
784
791
|
|
|
785
792
|
initRouter(router) {
|
|
786
793
|
router.post('/:controller', async (ctx, next) => {
|
|
787
|
-
const
|
|
794
|
+
const routerName = router.opts.prefix.substring(1)
|
|
795
|
+
const appName = this.config.includes.find(
|
|
796
|
+
(i) => i.routerName === routerName
|
|
797
|
+
)
|
|
788
798
|
const { app } = ctx
|
|
789
799
|
const { controller } = ctx.params
|
|
790
800
|
if (
|
|
@@ -796,7 +806,10 @@ class APP {
|
|
|
796
806
|
await next()
|
|
797
807
|
})
|
|
798
808
|
const handleRouter = async (ctx) => {
|
|
799
|
-
const
|
|
809
|
+
const routerName = router.opts.prefix.substring(1)
|
|
810
|
+
const appName = this.config.includes.find(
|
|
811
|
+
(i) => i.routerName === routerName
|
|
812
|
+
).dirName
|
|
800
813
|
const { app } = ctx
|
|
801
814
|
|
|
802
815
|
const { controller, fn, sub } = ctx.params
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q-koa",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"koa-static": "^5.0.0",
|
|
41
41
|
"koa-useragent": "^4.0.0",
|
|
42
42
|
"koa-xml-body": "^2.1.0",
|
|
43
|
+
"koa-proxies": "^0.12.2",
|
|
43
44
|
"lodash": "^4.17.15",
|
|
44
45
|
"lru-cache": "^5.1.1",
|
|
45
46
|
"mockjs": "^1.0.1-beta3",
|