2024-07-14 16:30:33 +00:00
|
|
|
import { Configuration, App } 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 { ReportMiddleware } from './middleware/report.js';
|
|
|
|
import { GlobalExceptionMiddleware } from './middleware/global-exception.js';
|
|
|
|
import { PreviewMiddleware } from './middleware/preview.js';
|
|
|
|
import { AuthorityMiddleware } from './middleware/authority.js';
|
|
|
|
import { logger } from './utils/logger.js';
|
|
|
|
import { ResetPasswdMiddleware } from './middleware/reset-passwd/middleware.js';
|
|
|
|
// import { DefaultErrorFilter } from './filter/default.filter.js';
|
|
|
|
// import { NotFoundFilter } from './filter/notfound.filter.js';
|
|
|
|
import DefaultConfig from './config/config.default.js';
|
|
|
|
import ProductionConfig from './config/config.production.js';
|
|
|
|
import PreviewConfig from './config/config.preview.js';
|
|
|
|
import UnittestConfig from './config/config.unittest.js';
|
|
|
|
|
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'],
|
|
|
|
},
|
|
|
|
],
|
2023-01-29 05:44:19 +00:00
|
|
|
importConfigs: [
|
|
|
|
{
|
2024-07-14 16:30:33 +00:00
|
|
|
default: DefaultConfig,
|
|
|
|
preview: PreviewConfig,
|
|
|
|
production: ProductionConfig,
|
|
|
|
unittest: UnittestConfig,
|
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([
|
|
|
|
ReportMiddleware,
|
|
|
|
//统一异常处理
|
|
|
|
GlobalExceptionMiddleware,
|
|
|
|
//预览模式限制修改id<1000的数据
|
|
|
|
PreviewMiddleware,
|
|
|
|
//授权处理
|
|
|
|
AuthorityMiddleware,
|
2024-06-15 18:06:44 +00:00
|
|
|
|
|
|
|
//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
|
|
|
}
|
|
|
|
}
|