q-koa 8.0.5 → 8.0.6

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