q-koa 13.1.3 → 13.1.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 CHANGED
@@ -10,6 +10,7 @@ const moment = require('moment')
10
10
  const { EventEmitter } = require('events')
11
11
  const nodeVm = require('vm')
12
12
  const LRU = require('lru-cache')
13
+ const axios = require('axios')
13
14
 
14
15
  const { Serve } = require('static-koa-router')
15
16
 
@@ -426,7 +427,8 @@ class APP {
426
427
  subscriber,
427
428
  appConfig: _.defaultsDeep(
428
429
  configExist ? require(path.resolve(__dirname, configPath)) : {},
429
- this.config.app
430
+ this.config.app,
431
+ { appName, ip: this.config.ip, port: this.port }
430
432
  ),
431
433
  }
432
434
  } else {
@@ -434,7 +436,8 @@ class APP {
434
436
  sequelize: db,
435
437
  appConfig: _.defaultsDeep(
436
438
  configExist ? require(path.resolve(__dirname, configPath)) : {},
437
- this.config.app
439
+ this.config.app,
440
+ { appName, ip: this.config.ip, port: this.port }
438
441
  ),
439
442
  }
440
443
  }
@@ -1204,6 +1207,19 @@ class APP {
1204
1207
  }
1205
1208
  return target
1206
1209
  }
1210
+
1211
+ if (
1212
+ where.hasOwnProperty('id') &&
1213
+ typeof where.id === 'string' &&
1214
+ where.id.includes('/')
1215
+ ) {
1216
+ const _result = await _.get(
1217
+ app[appName].controller,
1218
+ where.id.replace('/', '.')
1219
+ )(ctx)
1220
+ where.id = _result
1221
+ }
1222
+
1207
1223
  const formatWhere = _.mapValues(where, (item) => {
1208
1224
  if (!_.isObject(item)) return item
1209
1225
  return formatObj(item)
@@ -2211,6 +2227,26 @@ APP.getConfig = (app) => ({
2211
2227
  app.redisClient.publish('cache clear', target)
2212
2228
  } else {
2213
2229
  app.cache.set(target, null)
2230
+
2231
+ if (app.appConfig.appName) {
2232
+ const ipHost = (
2233
+ Array.isArray(app.appConfig.productionHost)
2234
+ ? app.appConfig.productionHost
2235
+ : [app.appConfig.productionHost]
2236
+ ).filter((url) => {
2237
+ return url.match(
2238
+ /^(http:\/\/|https:\/\/)?(\d{1,3}\.){3}\d{1,3}:\d{1,5}/
2239
+ )
2240
+ })
2241
+
2242
+ Promise.all(
2243
+ ipHost.map((host) => {
2244
+ return axios
2245
+ .get(`${host}/${app.appConfig.appName}/cache/clear?key=${target}`)
2246
+ .then((res) => res.data)
2247
+ })
2248
+ )
2249
+ }
2214
2250
  }
2215
2251
  },
2216
2252
  })
@@ -26,5 +26,8 @@ exports.clear = async (ctx) => {
26
26
  if (!key) return ctx.ERROR('缺key')
27
27
  app.cache.set(key, '')
28
28
 
29
+ const url = `${app.appConfig.ip}:${app.appConfig.port}`
30
+ app.service.log.push({ app, message: `${url}缓存${key}清除` })
31
+
29
32
  ctx.SUCCESS('ok')
30
33
  }
@@ -134,6 +134,7 @@ exports.html = async (ctx) => {
134
134
  const { code } = ctx.request.query
135
135
  if (!code) {
136
136
  ctx.body = `没有code`
137
+ return
137
138
  }
138
139
  const target = await app.model.setting.findOne({
139
140
  where: {
@@ -72,9 +72,15 @@ exports.initModel = async (ctx) => {
72
72
  return ctx.ERROR('请检查,model为空')
73
73
  }
74
74
  if (app.appConfig.productionHost) {
75
- const productionHost = Array.isArray(app.appConfig.productionHost)
76
- ? app.appConfig.productionHost
77
- : [app.appConfig.productionHost]
75
+ const productionHost = (
76
+ Array.isArray(app.appConfig.productionHost)
77
+ ? app.appConfig.productionHost
78
+ : [app.appConfig.productionHost]
79
+ ).filter((url) => {
80
+ return !url.match(
81
+ /^(http:\/\/|https:\/\/)?(\d{1,3}\.){3}\d{1,3}:\d{1,5}/
82
+ )
83
+ })
78
84
 
79
85
  for (const host of productionHost) {
80
86
  const { code, data: productionModel } = await axios
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.1.3",
3
+ "version": "13.1.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {