修改启动方式

This commit is contained in:
cool 2024-03-22 11:29:44 +08:00
parent d926285766
commit af8790537a
5 changed files with 16 additions and 32 deletions

View File

@ -38,6 +38,7 @@
"ws": "^8.16.0" "ws": "^8.16.0"
}, },
"devDependencies": { "devDependencies": {
"@midwayjs/cli": "^2.1.1",
"@midwayjs/mock": "^3.15.2", "@midwayjs/mock": "^3.15.2",
"@types/jest": "^29.5.12", "@types/jest": "^29.5.12",
"@types/koa": "^2.15.0", "@types/koa": "^2.15.0",
@ -54,13 +55,13 @@
}, },
"scripts": { "scripts": {
"start": "NODE_ENV=production node ./bootstrap.js", "start": "NODE_ENV=production node ./bootstrap.js",
"dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app.js", "dev": "cross-env && cross-env NODE_ENV=local TS_NODE_TYPE_CHECK=false TS_NODE_TRANSPILE_ONLY=true midway-bin dev --ts",
"cov": "jest --coverage", "cov": "midway-bin cov --ts",
"lint": "mwts check", "lint": "mwts check",
"lint:fix": "mwts fix", "lint:fix": "mwts fix",
"ci": "npm run cov", "ci": "npm run cov",
"build": "mwtsc --cleanOutDir", "build": "midway-bin build -c",
"pm2:start": "pm2 start ./bootstrap.js -i 2 --name cool-admin", "pm2:start": "pm2 start ./bootstrap.js -i max --name cool-admin",
"pm2:stop": "pm2 stop cool-admin & pm2 delete cool-admin" "pm2:stop": "pm2 stop cool-admin & pm2 delete cool-admin"
}, },
"midway-bin-clean": [ "midway-bin-clean": [

View File

@ -31,30 +31,17 @@ export class BaseAppEvent {
this.checkKeys(); this.checkKeys();
} }
@Event('onServerReady')
async onServerReady() {
setTimeout(() => {
this.coreLogger.info(
`
使 cool-admin 官网: https://cool-js.com
服务访问地址: http://127.0.0.1:${this.port}`
);
}, 2000);
}
/** /**
* *
*/ */
async checkConfig() { async checkConfig() {
if (this.config.base.jwt.secret == 'cool-admin-xxxxxx') { if (this.config.base.jwt.secret == 'cool-admin-xxxxxx') {
this.coreLogger.warn( this.coreLogger.warn(
'检测到模块[base] jwt.secret 配置是默认值,请不要关闭!即将自动修改...' '\x1B[36m 检测到模块[base] jwt.secret 配置是默认值,请不要关闭!即将自动修改... \x1B[0m'
); );
setTimeout(() => { setTimeout(() => {
const filePath = path.join( const filePath = path.join(
this.app.getBaseDir(), this.app.getBaseDir(),
'..',
'src',
'modules', 'modules',
'base', 'base',
'config.ts' 'config.ts'
@ -70,7 +57,7 @@ export class BaseAppEvent {
this.coreLogger.info( this.coreLogger.info(
'\x1B[36m [cool:module:base] midwayjs cool module base auto modify jwt.secret\x1B[0m' '\x1B[36m [cool:module:base] midwayjs cool module base auto modify jwt.secret\x1B[0m'
); );
}, 15000); }, 6000);
} }
} }
@ -80,13 +67,11 @@ export class BaseAppEvent {
async checkKeys() { async checkKeys() {
if (this.configKeys == 'cool-admin-keys-xxxxxx') { if (this.configKeys == 'cool-admin-keys-xxxxxx') {
this.coreLogger.warn( this.coreLogger.warn(
'检测到配置Keys是默认值请不要关闭即将自动修改...' '\x1B[36m 检测到基础配置[Keys] 是默认值,请不要关闭!即将自动修改... \x1B[0m'
); );
setTimeout(() => { setTimeout(() => {
const filePath = path.join( const filePath = path.join(
this.app.getBaseDir(), this.app.getBaseDir(),
'..',
'src',
'config', 'config',
'config.default.ts' 'config.default.ts'
); );
@ -101,7 +86,7 @@ export class BaseAppEvent {
this.coreLogger.info( this.coreLogger.info(
'\x1B[36m [cool:module:base] midwayjs cool keys auto modify \x1B[0m' '\x1B[36m [cool:module:base] midwayjs cool keys auto modify \x1B[0m'
); );
}, 15000); }, 6000);
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { DemoGoodsService } from '../../service/goods'; import { DemoGoodsService } from '../../service/goods';
import { DemoGoodsEntity } from '../../entity/goods'; import { DemoGoodsEntity } from '../../entity/goods';
import { Body, Inject, Post, Provide } from '@midwayjs/decorator'; import { Body, Config, Inject, Post, Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core'; import { CoolController, BaseController } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm'; import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';

View File

@ -18,10 +18,10 @@ export class DemoGoodsService extends BaseService {
async sqlPage(query) { async sqlPage(query) {
await this.demoGoodsEntity.save({ await this.demoGoodsEntity.save({
id: 11, id: 11,
title: '11', title: '标题',
price: 11, price: 99.0,
description: '11', description: '商品描述',
mainImage: '11', mainImage: 'https://cool-js.com/logo.png',
}); });
await this.demoGoodsEntity.delete({ id: 11 }); await this.demoGoodsEntity.delete({ id: 11 });
return this.sqlRenderPage( return this.sqlRenderPage(

View File

@ -30,13 +30,11 @@ export class UserAppEvent {
async checkConfig() { async checkConfig() {
if (this.config.user.jwt.secret == 'cool-app-xxxxxx') { if (this.config.user.jwt.secret == 'cool-app-xxxxxx') {
this.coreLogger.warn( this.coreLogger.warn(
'检测到模块[user] jwt.secret 配置是默认值,请不要关闭!即将自动修改...' '\x1B[36m 检测到模块[user] jwt.secret 配置是默认值,请不要关闭!即将自动修改... \x1B[0m'
); );
setTimeout(() => { setTimeout(() => {
const filePath = path.join( const filePath = path.join(
this.app.getBaseDir(), this.app.getBaseDir(),
'..',
'src',
'modules', 'modules',
'user', 'user',
'config.ts' 'config.ts'
@ -49,7 +47,7 @@ export class UserAppEvent {
this.coreLogger.info( this.coreLogger.info(
'\x1B[36m [cool:module:user] midwayjs cool module user auto modify jwt.secret\x1B[0m' '\x1B[36m [cool:module:user] midwayjs cool module user auto modify jwt.secret\x1B[0m'
); );
}, 15000); }, 6000);
} }
} }
} }