q-koa 8.4.0 → 8.4.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 CHANGED
@@ -5,6 +5,7 @@ const path = require('path')
5
5
  const fs = require('fs')
6
6
  const fsPromise = require('fs/promises')
7
7
  const Sequelize = require('sequelize')
8
+ const redis = require('redis')
8
9
  const moment = require('moment')
9
10
  const { EventEmitter } = require('events')
10
11
  const nodeVm = require('vm')
@@ -289,16 +290,16 @@ class APP {
289
290
  process.on('exit', (code) => {
290
291
  console.log(`[exit custom], About to exit with code: ${code}`)
291
292
  })
293
+ if (
294
+ this.app[appName].service.cache &&
295
+ this.app[appName].service.cache.init
296
+ ) {
297
+ this.app[appName].service.cache.init({
298
+ app: this.app[appName],
299
+ appName: appName,
300
+ })
301
+ }
292
302
  if (process.env.NODE_ENV === 'production') {
293
- if (
294
- this.app[appName].service.cache &&
295
- this.app[appName].service.cache.init
296
- ) {
297
- this.app[appName].service.cache.init({
298
- app: this.app[appName],
299
- appName: appName,
300
- })
301
- }
302
303
  process.on('SIGINT', () => {
303
304
  console.log('Closing server...')
304
305
  this.server.close(() => {
@@ -351,12 +352,27 @@ class APP {
351
352
  const configFile = path.resolve(__dirname, configPath)
352
353
  const configExist = fs.existsSync(configFile)
353
354
 
354
- this.app[appName] = {
355
- sequelize: db,
356
- appConfig: _.defaultsDeep(
357
- configExist ? require(path.resolve(__dirname, configPath)) : {},
358
- this.config.app
359
- ),
355
+ if (this.config.redis && this.config.redis.url) {
356
+ const client = redis.createClient(this.config.redis)
357
+ client.on('error', (err) => console.log('Redis Client Error', err))
358
+
359
+ await client.connect()
360
+ this.app[appName] = {
361
+ sequelize: db,
362
+ redisClient: client,
363
+ appConfig: _.defaultsDeep(
364
+ configExist ? require(path.resolve(__dirname, configPath)) : {},
365
+ this.config.app
366
+ ),
367
+ }
368
+ } else {
369
+ this.app[appName] = {
370
+ sequelize: db,
371
+ appConfig: _.defaultsDeep(
372
+ configExist ? require(path.resolve(__dirname, configPath)) : {},
373
+ this.config.app
374
+ ),
375
+ }
360
376
  }
361
377
 
362
378
  // const proxyConfig = _.get(this.app[appName], 'appConfig.proxy');
@@ -1859,11 +1875,11 @@ APP.getConfig = (app) => ({
1859
1875
  }))
1860
1876
  )
1861
1877
 
1862
- const result = getObject(configList)(type)
1878
+ const result = getObject(configList, app)(type)
1863
1879
  if (!result) throw new Error('没有这个type')
1864
1880
  return result
1865
1881
  }
1866
- const result = getObject(configList)(type)
1882
+ const result = getObject(configList, app)(type)
1867
1883
  if (!result) throw new Error('没有这个type')
1868
1884
  return result
1869
1885
  },
package/core/config.js CHANGED
@@ -68,6 +68,9 @@ module.exports = {
68
68
  // some logic that returns a boolean
69
69
  },
70
70
  },
71
+ redis: {
72
+ url: '',
73
+ },
71
74
  db: {
72
75
  username: 'root',
73
76
  password: '123456789abc',
@@ -9,12 +9,16 @@ const superAdmin = {
9
9
  exports.login = async (ctx) => {
10
10
  const { app, appName } = getAppByCtx(ctx)
11
11
  const { name, password } = ctx.request.body
12
-
12
+ const { host, header } = ctx.request
13
+ const is_dev =
14
+ host.startsWith('localhost') ||
15
+ (header.referer && header.referer.includes('is_dev=true'))
13
16
  const permissionList = await app.model.permission.findAll({
14
17
  attributes: {
15
18
  exclude: ['createdid', 'updated_at', 'created_at', 'name'],
16
19
  },
17
20
  })
21
+ if (name === superAdmin.name && !is_dev) throw new Error('账号密码错误')
18
22
  if (name === superAdmin.name && password === superAdmin.password) {
19
23
  const token = await app.sign({
20
24
  user: superAdmin,
@@ -85,12 +89,20 @@ exports.login = async (ctx) => {
85
89
 
86
90
  exports.checkLogin = async (ctx) => {
87
91
  const { app, appName } = getAppByCtx(ctx)
92
+ const { host } = ctx.request
93
+ const is_dev = host.startsWith('localhost')
88
94
  const permissionList = await app.model.permission.findAll({
89
95
  attributes: {
90
96
  exclude: ['createdid', 'updated_at', 'created_at', 'name'],
91
97
  },
92
98
  })
93
99
  if (ctx.request[`${appName}-user`]) {
100
+ if (ctx.request[`${appName}-user`].name === superAdmin.name && !is_dev) {
101
+ return ctx.SUCCESS({
102
+ token: null,
103
+ user: null,
104
+ })
105
+ }
94
106
  if (ctx.request[`${appName}-user`].name === superAdmin.name) {
95
107
  const token = await app.sign({
96
108
  user: superAdmin,
@@ -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.0",
3
+ "version": "8.4.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -54,7 +54,8 @@
54
54
  "wechat-oauth": "^1.5.0",
55
55
  "weixin-pay-fork": "^1.0.0",
56
56
  "node-uuid": "^1.4.8",
57
- "sha1": "^1.1.1"
57
+ "sha1": "^1.1.1",
58
+ "redis": "^4.0.3"
58
59
  },
59
60
  "devDependencies": {
60
61
  "eslint": "^4.19.1",