MCPcopy Create free account
hub / github.com/baiwumm/react-admin / bootstrap

Function bootstrap

Xmw_server/src/main.ts:28–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26import { logger } from './middleware/logger.middleware'; // 日志收集中间件
27
28async function bootstrap() {
29 const app = await NestFactory.create(AppModule);
30 app.use(express.json());
31 app.use(express.urlencoded({ extended: true }));
32 //日志相关
33 app.use(logger); // 所有请求都打印日志
34
35 // 启动cors跨域
36 app.enableCors();
37
38 // 配置 session
39 app.use(
40 session({
41 secret: 'baiwumm', // 签名
42 resave: false, // 强制保存 sseion 即使它并没有变化,默认为true
43 saveUninitialized: false, // 强制将未初始化的 session 存储
44 }),
45 );
46
47 // 全局参数校验
48 app.useGlobalPipes(new ValidationPipe());
49
50 // 全局请求拦截中间件
51 // app.use(requestMiddleware);
52
53 // 错误异常捕获 和 过滤处理
54 app.useGlobalFilters(new AllExceptionsFilter());
55 app.useGlobalFilters(new HttpExceptionFilter()); // 全局统一异常返回体
56
57 // 全局响应拦截器,格式化返回体
58 app.useGlobalInterceptors(new HttpReqTransformInterceptor<Response>());
59 app.useGlobalInterceptors(new TransformInterceptor()); // 全局拦截器,用来收集日志
60
61 // 配置文件访问 文件夹为静态目录,以达到可直接访问下面文件的目的
62 const rootDir = join(__dirname, '..');
63 app.use('/static', express.static(join(rootDir, '/upload')));
64
65 // 全局添加接口前缀
66 // app.setGlobalPrefix(process.env.REQUEST_URL_PREFIX);
67
68 // 构建swagger文档
69 const options = new DocumentBuilder()
70 .setTitle(process.env.SWAGGER_UI_TITLE)
71 .addBearerAuth()
72 .setDescription(process.env.SWAGGER_UI_DESC)
73 .setVersion(process.env.SWAGGER_API_VERSION)
74 .build();
75 const document = SwaggerModule.createDocument(app, options);
76 SwaggerModule.setup(process.env.SWAGGER_SETUP_PATH, app, document);
77 await app.listen(App_configuration().port, () => {
78 Logger.info(
79 `服务已经启动,接口请访问:http://www.localhost:${App_configuration().port
80 }`,
81 );
82 });
83}
84bootstrap();

Callers 1

main.tsFile · 0.85

Calls 2

useMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected