q-koa 8.4.2 → 8.4.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.
package/core/app.js CHANGED
@@ -68,6 +68,7 @@ const connectDatabase = (database) => (config) => {
68
68
 
69
69
  const defaultConfig = require('./config')
70
70
 
71
+ const is_dev = process.env.NODE_ENV !== 'production'
71
72
  class APP {
72
73
  constructor(_config) {
73
74
  const config = _.defaultsDeep(_config, defaultConfig)
@@ -290,16 +291,16 @@ class APP {
290
291
  process.on('exit', (code) => {
291
292
  console.log(`[exit custom], About to exit with code: ${code}`)
292
293
  })
293
- if (process.env.NODE_ENV === 'production') {
294
- if (
295
- this.app[appName].service.cache &&
296
- this.app[appName].service.cache.init
297
- ) {
298
- this.app[appName].service.cache.init({
299
- app: this.app[appName],
300
- appName: appName,
301
- })
302
- }
294
+ if (
295
+ this.app[appName].service.cache &&
296
+ this.app[appName].service.cache.init
297
+ ) {
298
+ this.app[appName].service.cache.init({
299
+ app: this.app[appName],
300
+ appName: appName,
301
+ })
302
+ }
303
+ if (!is_dev) {
303
304
  process.on('SIGINT', () => {
304
305
  console.log('Closing server...')
305
306
  this.server.close(() => {
@@ -338,7 +339,7 @@ class APP {
338
339
 
339
340
  try {
340
341
  const db = connectDatabase(appName)(this.config.db)
341
- if (process.env.NODE_ENV === 'production') {
342
+ if (!is_dev) {
342
343
  if (!dbFlag) {
343
344
  console.log(chalk.green(`检查${appName}数据库`))
344
345
  await db.authenticate()
@@ -365,7 +366,7 @@ class APP {
365
366
  this.config.app
366
367
  ),
367
368
  }
368
- }else{
369
+ } else {
369
370
  this.app[appName] = {
370
371
  sequelize: db,
371
372
  appConfig: _.defaultsDeep(
@@ -374,7 +375,6 @@ class APP {
374
375
  ),
375
376
  }
376
377
  }
377
-
378
378
 
379
379
  // const proxyConfig = _.get(this.app[appName], 'appConfig.proxy');
380
380
  // const taskConfig = _.get(this.app[appName], 'appConfig.task', {
@@ -1742,7 +1742,9 @@ class APP {
1742
1742
  if (_.get(app, `${appName}.afterExecute.${controller}.${fn}`)) {
1743
1743
  app[appName].afterExecute[controller][fn](ctx)
1744
1744
  .then((res) => {
1745
- console.log('afterUpdate', res)
1745
+ if (is_dev) {
1746
+ console.log('afterUpdate', res)
1747
+ }
1746
1748
  })
1747
1749
  .catch((e) => {
1748
1750
  console.log('错误', e)
@@ -1876,11 +1878,11 @@ APP.getConfig = (app) => ({
1876
1878
  }))
1877
1879
  )
1878
1880
 
1879
- const result = getObject(configList)(type)
1881
+ const result = getObject(configList, app)(type)
1880
1882
  if (!result) throw new Error('没有这个type')
1881
1883
  return result
1882
1884
  }
1883
- const result = getObject(configList)(type)
1885
+ const result = getObject(configList, app)(type)
1884
1886
  if (!result) throw new Error('没有这个type')
1885
1887
  return result
1886
1888
  },
package/core/config.js CHANGED
@@ -5,6 +5,7 @@ module.exports = {
5
5
  static: {
6
6
  dir: 'public',
7
7
  },
8
+ is_check_admin: false,
8
9
  log: {
9
10
  request: true,
10
11
  },
@@ -12,6 +12,7 @@ exports.login = async (ctx) => {
12
12
  const { host, header } = ctx.request
13
13
  const is_dev =
14
14
  host.startsWith('localhost') ||
15
+ !app.appConfig.is_check_admin ||
15
16
  (header.referer && header.referer.includes('is_dev=true'))
16
17
  const permissionList = await app.model.permission.findAll({
17
18
  attributes: {
@@ -107,7 +107,7 @@ exports.loadModel = async ({ app, appName }) => {
107
107
  defaultValue = `${model[name].defaultValue}`
108
108
  }
109
109
  if (Array.isArray(model[name].defaultValue)) {
110
- defaultValue = '[]'
110
+ defaultValue = JSON.stringify(model[name].defaultValue)
111
111
  }
112
112
  if (
113
113
  Object.prototype.toString.call(model[name].defaultValue) ===
@@ -16,6 +16,15 @@ exports.getList = (config) => (type) => {
16
16
  }
17
17
 
18
18
  exports.getObject = (config) => (type) => {
19
+ if (app) {
20
+ const applicationList = await app.cache.get('application')
21
+ if (
22
+ applicationList &&
23
+ applicationList.find((item) => item.config === type)
24
+ ) {
25
+ return applicationList.find((item) => item.config === type)
26
+ }
27
+ }
19
28
  const obj = config.find((i) => i.code === type)
20
29
  if (!obj) throw new Error(`找不到${type}相关设置`)
21
30
  const list = config.filter((i) => i.parent_id === obj.id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.4.2",
3
+ "version": "8.4.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {