mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-31 13:08:10 +00:00
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import {
|
|
App,
|
|
ILifeCycle,
|
|
ILogger,
|
|
IMidwayContainer,
|
|
Inject,
|
|
Logger,
|
|
} from '@midwayjs/core';
|
|
import { Configuration } from '@midwayjs/core';
|
|
import * as DefaultConfig from './config/config.default';
|
|
import { CoolExceptionFilter } from './exception/filter';
|
|
import { FuncUtil } from './util/func';
|
|
import * as koa from '@midwayjs/koa';
|
|
import { CoolModuleConfig } from './module/config';
|
|
import { CoolModuleImport } from './module/import';
|
|
import { CoolEventManager } from './event';
|
|
import { CoolEps } from './rest/eps';
|
|
import { CoolDecorator } from './decorator';
|
|
import * as cache from '@midwayjs/cache-manager';
|
|
import * as _cache from '@midwayjs/cache';
|
|
|
|
@Configuration({
|
|
namespace: 'cool',
|
|
imports: [_cache, cache],
|
|
importConfigs: [
|
|
{
|
|
default: DefaultConfig,
|
|
},
|
|
],
|
|
})
|
|
export class CoolConfiguration implements ILifeCycle {
|
|
@Logger()
|
|
coreLogger: ILogger;
|
|
|
|
@App()
|
|
app: koa.Application;
|
|
|
|
@Inject()
|
|
coolEventManager: CoolEventManager;
|
|
|
|
async onReady(container: IMidwayContainer) {
|
|
this.coolEventManager.emit('onReady');
|
|
// 处理模块配置
|
|
await container.getAsync(CoolModuleConfig);
|
|
// 常用函数处理
|
|
await container.getAsync(FuncUtil);
|
|
// 异常处理
|
|
this.app.useFilter([CoolExceptionFilter]);
|
|
// 装饰器
|
|
await container.getAsync(CoolDecorator);
|
|
|
|
// 缓存设置为全局
|
|
// global["COOL-CACHE"] = await container.getAsync(CacheManager);
|
|
// // 清除 location
|
|
// setTimeout(() => {
|
|
// location.clean();
|
|
// this.coreLogger.info("\x1B[36m [cool:core] location clean \x1B[0m");
|
|
// }, 10000);
|
|
}
|
|
|
|
async onConfigLoad() {}
|
|
|
|
async onServerReady(container: IMidwayContainer) {
|
|
// 事件
|
|
await (await container.getAsync(CoolEventManager)).init();
|
|
// 导入模块数据
|
|
(await container.getAsync(CoolModuleImport)).init();
|
|
// 实体与路径
|
|
const eps: CoolEps = await container.getAsync(CoolEps);
|
|
eps.init();
|
|
this.coolEventManager.emit('onServerReady');
|
|
// location.clean();
|
|
}
|
|
}
|