mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-03-17 19:23:29 +00:00
1111
This commit is contained in:
parent
2c755d84e5
commit
97676570c8
@ -4,10 +4,13 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@midwayjs/web": "^2.7.3",
|
|
||||||
"@midwayjs/decorator": "^2.7.0",
|
"@midwayjs/decorator": "^2.7.0",
|
||||||
|
"@midwayjs/orm": "^1.3.0",
|
||||||
|
"@midwayjs/web": "^2.7.3",
|
||||||
"egg": "^2.29.1",
|
"egg": "^2.29.1",
|
||||||
"egg-scripts": "^2.13.0"
|
"egg-scripts": "^2.13.0",
|
||||||
|
"midwayjs-cool-core": "file:/Users/ap/Documents/srcs/cool-admin/midway-core/core/dist",
|
||||||
|
"mysql2": "^2.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@midwayjs/cli": "^1.2.40",
|
"@midwayjs/cli": "^1.2.40",
|
||||||
@ -17,8 +20,8 @@
|
|||||||
"@types/jest": "^26.0.20",
|
"@types/jest": "^26.0.20",
|
||||||
"@types/node": "14",
|
"@types/node": "14",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"mwts": "^1.1.2",
|
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
|
"mwts": "^1.1.2",
|
||||||
"ts-jest": "^26.5.0",
|
"ts-jest": "^26.5.0",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.1.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -8,15 +8,29 @@ export default (appInfo: EggAppInfo) => {
|
|||||||
config.keys = appInfo.name + 'cool-admin-next';
|
config.keys = appInfo.name + 'cool-admin-next';
|
||||||
|
|
||||||
// 中间件
|
// 中间件
|
||||||
//config.middleware = [];
|
config.middleware = [];
|
||||||
|
|
||||||
|
// 关闭安全校验
|
||||||
config.security = {
|
config.security = {
|
||||||
csrf: {
|
csrf: {
|
||||||
enable: false,
|
enable: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 替换成midway的日志
|
// cool-admin特有的配置
|
||||||
|
config.cool = {
|
||||||
|
// 全局路由前缀
|
||||||
|
router: {
|
||||||
|
prefix: ''
|
||||||
|
},
|
||||||
|
// 分页配置
|
||||||
|
page: {
|
||||||
|
// 分页查询每页条数
|
||||||
|
size: 15,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将egg日志替换成midway
|
||||||
config.midwayFeature = {
|
config.midwayFeature = {
|
||||||
replaceEggLogger: true
|
replaceEggLogger: true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||||
|
|
||||||
|
export type DefaultConfig = PowerPartial<EggAppConfig>;
|
||||||
|
|
||||||
|
export default (appInfo: EggAppInfo) => {
|
||||||
|
const config = {} as DefaultConfig;
|
||||||
|
|
||||||
|
config.orm = {
|
||||||
|
type: 'mysql',
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 3306,
|
||||||
|
username: 'root',
|
||||||
|
password: '123123',
|
||||||
|
database: 'cool-admin-next',
|
||||||
|
synchronize: true,
|
||||||
|
logging: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
config.logger = {
|
||||||
|
coreLogger: {
|
||||||
|
consoleLevel: 'INFO'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
@ -1,17 +1,26 @@
|
|||||||
import { App, Configuration } from '@midwayjs/decorator';
|
import { App, Configuration } from '@midwayjs/decorator';
|
||||||
import { ILifeCycle } from '@midwayjs/core';
|
import { ILifeCycle, IMidwayContainer } from '@midwayjs/core';
|
||||||
import { Application } from 'egg';
|
import { Application } from 'egg';
|
||||||
|
// import * as orm from '@midwayjs/orm';
|
||||||
|
import * as cool from 'midwayjs-cool-core';
|
||||||
|
|
||||||
@Configuration()
|
@Configuration({
|
||||||
|
imports: [
|
||||||
|
// cool-admin 官方组件 https://www.cool-js.com
|
||||||
|
cool
|
||||||
|
//orm
|
||||||
|
]
|
||||||
|
})
|
||||||
export class ContainerLifeCycle implements ILifeCycle {
|
export class ContainerLifeCycle implements ILifeCycle {
|
||||||
|
|
||||||
@App()
|
@App()
|
||||||
app: Application;
|
app: Application;
|
||||||
|
// 应用启动完成
|
||||||
|
async onReady(container?: IMidwayContainer) {
|
||||||
|
//this.app.use(await this.app.generateMiddleware('reportMiddleware'));
|
||||||
|
}
|
||||||
|
// 应用停止
|
||||||
|
async onStop() {
|
||||||
|
|
||||||
async onReady() {
|
|
||||||
this.app.use(async (ctx, next) => {
|
|
||||||
console.log('这边请求到了')
|
|
||||||
await next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
import { Inject, Controller, Provide, Query, Get } from '@midwayjs/decorator';
|
|
||||||
import { Context } from 'egg';
|
|
||||||
import { UserService } from '../service/user';
|
|
||||||
|
|
||||||
@Provide()
|
|
||||||
@Controller('/api')
|
|
||||||
export class APIController {
|
|
||||||
@Inject()
|
|
||||||
ctx: Context;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
userService: UserService;
|
|
||||||
|
|
||||||
@Get('/get_user')
|
|
||||||
async getUser(@Query() uid) {
|
|
||||||
const user = await this.userService.getUser({ uid });
|
|
||||||
return { success: true, message: 'OK', data: user };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +1,15 @@
|
|||||||
import { Controller, Get, Provide } from '@midwayjs/decorator';
|
import { Get, Provide, Inject, Query } from '@midwayjs/decorator';
|
||||||
|
import { CoolController, CoolCache } from 'midwayjs-cool-core';
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Controller('/')
|
@CoolController()
|
||||||
export class HomeController {
|
export class HomeController {
|
||||||
@Get('/')
|
@Inject('cool-core:coolCache')
|
||||||
async home() {
|
coolCache: CoolCache;
|
||||||
return 'Hello Midwayjs!';
|
|
||||||
|
@Get('/1')
|
||||||
|
async home(@Query() data: string) {
|
||||||
|
console.log(await this.coolCache.set('a', data))
|
||||||
|
return await this.coolCache.get('a');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/controller/home1.ts
Executable file
15
src/controller/home1.ts
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
import { Get, Provide, Inject } from '@midwayjs/decorator';
|
||||||
|
import { CoolController, CoolCache } from 'midwayjs-cool-core';
|
||||||
|
|
||||||
|
@Provide()
|
||||||
|
@CoolController()
|
||||||
|
export class Home1Controller {
|
||||||
|
@Inject('cool-core:coolCache')
|
||||||
|
coolCache: CoolCache;
|
||||||
|
@Get('/1')
|
||||||
|
async home() {
|
||||||
|
const data = await this.coolCache.get('a');
|
||||||
|
console.log('获得到的数据', data)
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/middleware/report.ts
Normal file
16
src/middleware/report.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Provide } from '@midwayjs/decorator';
|
||||||
|
import { IWebMiddleware, IMidwayWebNext } from '@midwayjs/web';
|
||||||
|
import { Context } from 'egg';
|
||||||
|
|
||||||
|
@Provide()
|
||||||
|
export class ReportMiddleware implements IWebMiddleware {
|
||||||
|
|
||||||
|
resolve() {
|
||||||
|
return async (ctx: Context, next: IMidwayWebNext) => {
|
||||||
|
const startTime = Date.now();
|
||||||
|
await next();
|
||||||
|
console.log('请求时间', Date.now() - startTime);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user