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