From 755a750d223b226cc43ad26d42449c151503cebb Mon Sep 17 00:00:00 2001 From: cool_team Date: Wed, 31 May 2023 11:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E5=85=A8=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configuration.ts | 30 ++++++++++++++++++++++++++++-- src/modules/base/config.ts | 2 +- src/modules/user/config.ts | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index c112b89..010a5af 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -1,5 +1,5 @@ import * as orm from '@midwayjs/typeorm'; -import { Configuration, App } from '@midwayjs/decorator'; +import { Configuration, App, Config, Inject } from '@midwayjs/decorator'; import * as koa from '@midwayjs/koa'; import * as validate from '@midwayjs/validate'; import * as info from '@midwayjs/info'; @@ -12,6 +12,7 @@ import * as cool from '@cool-midway/core'; import * as cloud from '@cool-midway/cloud'; import * as file from '@cool-midway/file'; import * as sms from '@cool-midway/sms'; +import { ILogger } from '@midwayjs/logger'; // import * as rpc from '@cool-midway/rpc'; // import * as task from '@cool-midway/task'; // import * as pay from '@cool-midway/pay'; @@ -60,5 +61,30 @@ export class ContainerLifeCycle { @App() app: koa.Application; - async onReady() {} + @Inject() + logger: ILogger; + + @Config('module') + config; + + async onReady() { + // 检查配置 + await this.checkConfig(); + } + + /** + * 检查配置 + */ + async checkConfig() { + if (this.config.base.jwt.secret === 'cool-admin-xxxxxx') { + this.logger.warn( + '安全起见,请修改[base]模块配置文件 config.ts 中的 jwt.secret 为随机字符串' + ); + } + if (this.config.user.jwt.secret == 'cool-app-xxxxxx') { + this.logger.warn( + '安全起见,请修改[user]模块配置文件 config.ts 中的 jwt.secret 为随机字符串' + ); + } + } } diff --git a/src/modules/base/config.ts b/src/modules/base/config.ts index 8e5048e..c512e64 100644 --- a/src/modules/base/config.ts +++ b/src/modules/base/config.ts @@ -20,7 +20,7 @@ export default () => { // 单点登录 sso: false, // 注意: 最好重新修改,防止破解 - secret: 'FJPOJSFPAFKPA', + secret: 'cool-admin-xxxxxx', // token token: { // 2小时过期,需要用刷新token diff --git a/src/modules/user/config.ts b/src/modules/user/config.ts index f1b8e62..2c2a30d 100644 --- a/src/modules/user/config.ts +++ b/src/modules/user/config.ts @@ -45,7 +45,7 @@ export default () => { // 刷新token 过期时间,单位秒 refreshExpire: 60 * 60 * 24 * 30, // jwt 秘钥 - secret: 'DJKPASKDPA', + secret: 'cool-app-xxxxxx', }, } as ModuleConfig; };