mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-01-03 08:58:12 +00:00
111
This commit is contained in:
parent
78b22244cf
commit
73b75eeb00
14
package.json
14
package.json
@ -4,27 +4,27 @@
|
||||
"description": "",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@midwayjs/decorator": "^2.7.0",
|
||||
"@midwayjs/decorator": "^2.7.5",
|
||||
"@midwayjs/orm": "^1.3.0",
|
||||
"@midwayjs/web": "^2.7.3",
|
||||
"egg": "^2.29.1",
|
||||
"@midwayjs/web": "^2.7.7",
|
||||
"egg": "^2.29.3",
|
||||
"egg-scripts": "^2.13.0",
|
||||
"midwayjs-cool-core": "file:/Users/ap/Documents/srcs/cool-admin/midway-core/core/dist",
|
||||
"midwayjs-cool-redis": "file:/Users/ap/Documents/srcs/cool-admin/midway-core/redis/dist",
|
||||
"mysql2": "^2.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@midwayjs/cli": "^1.2.40",
|
||||
"@midwayjs/cli": "^1.2.41",
|
||||
"@midwayjs/egg-ts-helper": "^1.0.5",
|
||||
"@midwayjs/luckyeye": "^1.0.2",
|
||||
"@midwayjs/mock": "^2.7.2",
|
||||
"@midwayjs/mock": "^2.7.7",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/node": "14",
|
||||
"cross-env": "^7.0.3",
|
||||
"jest": "^26.6.3",
|
||||
"mwts": "^1.1.2",
|
||||
"ts-jest": "^26.5.0",
|
||||
"typescript": "^4.1.3"
|
||||
"ts-jest": "^26.5.1",
|
||||
"typescript": "^4.1.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
|
||||
@ -8,7 +8,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
config.keys = appInfo.name + 'cool-admin-next';
|
||||
|
||||
// 中间件
|
||||
config.middleware = [];
|
||||
config.middleware = ['reportMiddleware'];
|
||||
|
||||
// 关闭安全校验
|
||||
config.security = {
|
||||
|
||||
@ -3,13 +3,14 @@ import { ILifeCycle, IMidwayContainer } from '@midwayjs/core';
|
||||
import { Application } from 'egg';
|
||||
import * as orm from '@midwayjs/orm';
|
||||
import * as cool from 'midwayjs-cool-core';
|
||||
import * as bodyParser from 'koa-bodyparser';
|
||||
//import * as redis from 'midwayjs-cool-redis';
|
||||
|
||||
@Configuration({
|
||||
// 注意组件顺序 cool 有依赖orm组件, 所以必须放在,orm组件之后 cool的其他组件必须放在cool 核心组件之后
|
||||
imports: [
|
||||
// 必须,不可移除, https://typeorm.io 打不开? https://typeorm.biunav.com/zh/
|
||||
orm,
|
||||
//orm,
|
||||
// 必须,不可移除, cool-admin 官方组件 https://www.cool-js.com
|
||||
cool,
|
||||
//redis
|
||||
@ -22,19 +23,11 @@ export class ContainerLifeCycle implements ILifeCycle {
|
||||
app: Application;
|
||||
// 应用启动完成
|
||||
async onReady(container?: IMidwayContainer) {
|
||||
// this.app.use(async (ctx, next)=>{
|
||||
// console.log('执行了')
|
||||
// this.app.use(bodyParser());
|
||||
// this.app.use(async (ctx: Context, next)=>{
|
||||
// console.log(ctx.request.body)
|
||||
// });
|
||||
this.app.router.get('/dev', (ctx, next) => {
|
||||
console.log('进来中间件了');
|
||||
ctx.status = 200
|
||||
ctx.body = {
|
||||
a: 1,
|
||||
b: 2
|
||||
};
|
||||
}, (ctx) => {
|
||||
console.log('调用路由')
|
||||
})
|
||||
|
||||
}
|
||||
// 应用停止
|
||||
async onStop() {
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { Get, Provide, Inject, Query } from '@midwayjs/decorator';
|
||||
import { CoolController, CoolCache } from 'midwayjs-cool-core';
|
||||
import { Get, Provide, Inject, Query, Body, ALL, Post, Validate } from '@midwayjs/decorator';
|
||||
import { CoolController, CoolCache, BaseController, RESCODE } from 'midwayjs-cool-core';
|
||||
//import { InjectEntityModel } from '@midwayjs/orm';
|
||||
import { User } from '../entity/user';
|
||||
|
||||
import { TestDTO } from '../dto/test';
|
||||
|
||||
@Provide()
|
||||
@CoolController({ api: ['add'], model: User })
|
||||
export class HomeController {
|
||||
@CoolController({
|
||||
api: ['info', 'add'],
|
||||
entity: User,
|
||||
infoIgnoreProperty: ['age']
|
||||
})
|
||||
export class HomeController extends BaseController {
|
||||
@Inject('cool:cache')
|
||||
coolCache: CoolCache;
|
||||
|
||||
@ -16,4 +20,9 @@ export class HomeController {
|
||||
await this.coolCache.set('a', data);
|
||||
return await this.coolCache.get('a');
|
||||
}
|
||||
|
||||
@Post('/2')
|
||||
async 2(@Body(ALL) test: TestDTO) {
|
||||
return this.fail('哈哈', RESCODE.VALIDATEFAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import { Rule, RuleType } from "@midwayjs/decorator";
|
||||
|
||||
export class UserDTO {
|
||||
@Rule(RuleType.number().required())
|
||||
id: number;
|
||||
export class TestDTO {
|
||||
|
||||
@Rule(RuleType.string().required())
|
||||
firstName: string;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { IWebMiddleware, IMidwayWebNext } from '@midwayjs/web';
|
||||
import { Context } from 'egg';
|
||||
import { IWebMiddleware, IMidwayWebNext, IMidwayWebContext } from '@midwayjs/web';
|
||||
|
||||
@Provide()
|
||||
export class ReportMiddleware implements IWebMiddleware {
|
||||
|
||||
resolve() {
|
||||
return async (ctx: Context, next: IMidwayWebNext) => {
|
||||
resolve() {
|
||||
return async (ctx: IMidwayWebContext, next: IMidwayWebNext) => {
|
||||
console.log('请求进来了')
|
||||
const startTime = Date.now();
|
||||
await next();
|
||||
console.log('请求时间', Date.now() - startTime);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user