certd/packages/ui/certd-server/src/configuration.ts

79 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-08-13 12:30:42 +00:00
import { App, Configuration } from '@midwayjs/core';
2023-01-29 05:44:19 +00:00
import * as koa from '@midwayjs/koa';
2023-05-25 02:33:42 +00:00
import * as orm from '@midwayjs/typeorm';
import * as cache from '@midwayjs/cache';
2024-07-14 16:30:33 +00:00
import * as validate from '@midwayjs/validate';
import * as info from '@midwayjs/info';
2023-05-25 04:38:29 +00:00
import * as staticFile from '@midwayjs/static-file';
2024-07-14 16:30:33 +00:00
import * as cron from './modules/plugin/cron/index.js';
import * as flyway from '@certd/midway-flyway-js';
import cors from '@koa/cors';
import { GlobalExceptionMiddleware } from './middleware/global-exception.js';
import { PreviewMiddleware } from './middleware/preview.js';
import { AuthorityMiddleware } from './middleware/authority.js';
2024-10-03 14:03:49 +00:00
import { logger } from '@certd/pipeline';
2024-07-14 16:30:33 +00:00
import { ResetPasswdMiddleware } from './middleware/reset-passwd/middleware.js';
import DefaultConfig from './config/config.default.js';
2024-10-03 14:03:49 +00:00
import * as libServer from '@certd/lib-server';
import * as commercial from '@certd/commercial-core';
2024-07-18 03:17:13 +00:00
process.on('uncaughtException', error => {
console.error('未捕获的异常:', error);
// 在这里可以添加日志记录、发送错误通知等操作
});
2023-01-29 05:44:19 +00:00
@Configuration({
2024-07-14 16:30:33 +00:00
imports: [
koa,
orm,
cache,
flyway,
cron,
staticFile,
validate,
{
component: info,
enabledEnvironment: ['local'],
},
2024-10-03 14:03:49 +00:00
libServer,
commercial,
2024-07-14 16:30:33 +00:00
],
2023-01-29 05:44:19 +00:00
importConfigs: [
{
2024-07-14 16:30:33 +00:00
default: DefaultConfig,
2023-01-29 05:44:19 +00:00
},
],
})
2024-07-14 16:30:33 +00:00
export class MainConfiguration {
@App('koa')
2023-01-29 05:44:19 +00:00
app: koa.Application;
async onReady() {
2024-07-14 16:30:33 +00:00
// add middleware
2024-07-18 03:17:13 +00:00
// this.app.useMiddleware([ReportMiddleware]);
2024-07-14 16:30:33 +00:00
// add filter
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
2023-01-29 05:44:19 +00:00
//跨域
this.app.use(
cors({
origin: '*',
})
);
// bodyparser options see https://github.com/koajs/bodyparser
//this.app.use(bodyParser());
//请求日志打印
this.app.useMiddleware([
//统一异常处理
GlobalExceptionMiddleware,
//预览模式限制修改id<1000的数据
PreviewMiddleware,
//授权处理
AuthorityMiddleware,
//resetPasswd,重置密码模式下不提供服务
ResetPasswdMiddleware,
2023-01-29 05:44:19 +00:00
]);
2023-06-29 01:31:26 +00:00
logger.info('当前环境:', this.app.getEnv()); // prod
2023-01-29 05:44:19 +00:00
}
}