fix(server): node imports order (#5583)

This commit is contained in:
liuyi
2024-01-14 05:47:56 +00:00
parent 18907ebe57
commit 4c49b62ab7
16 changed files with 109 additions and 101 deletions
+39 -35
View File
@@ -1,38 +1,42 @@
import { DynamicModule, Module, Type } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { NestFactory } from '@nestjs/core';
import type { NestExpressApplication } from '@nestjs/platform-express';
import cookieParser from 'cookie-parser';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
import { AppController } from './app.controller';
import { CacheInterceptor, CacheModule } from './fundamentals/cache';
import { ConfigModule } from './fundamentals/config';
import { EventModule } from './fundamentals/event';
import { MailModule } from './fundamentals/mailer';
import { MetricsModule } from './fundamentals/metrics';
import { PrismaModule } from './fundamentals/prisma';
import { SessionModule } from './fundamentals/session';
import { RateLimiterModule } from './fundamentals/throttler';
import { BusinessModules } from './modules';
import { AuthModule } from './modules/auth';
import { CacheRedis } from './fundamentals/cache/redis';
import { RedisIoAdapter } from './fundamentals/websocket';
import { ExceptionLogger } from './middleware/exception-logger';
import { serverTimingAndCache } from './middleware/timing';
export const FunctionalityModules: Array<Type | DynamicModule> = [
ConfigModule.forRoot(),
CacheModule,
PrismaModule,
MetricsModule,
EventModule,
SessionModule,
RateLimiterModule,
AuthModule,
MailModule,
];
export async function createApp() {
const { AppModule } = await import('./app.module');
@Module({
providers: [
{
provide: APP_INTERCEPTOR,
useClass: CacheInterceptor,
},
],
imports: [...FunctionalityModules, ...BusinessModules],
controllers: [AppController],
})
export class AppModule {}
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
cors: true,
rawBody: true,
bodyParser: true,
logger: AFFiNE.affine.stable ? ['log'] : ['verbose'],
});
app.use(serverTimingAndCache);
app.use(
graphqlUploadExpress({
// TODO: dynamic limit by quota
maxFileSize: 100 * 1024 * 1024,
maxFiles: 5,
})
);
app.useGlobalFilters(new ExceptionLogger());
app.use(cookieParser());
if (AFFiNE.redis.enabled) {
const redis = app.get(CacheRedis, { strict: false });
const redisIoAdapter = new RedisIoAdapter(app);
await redisIoAdapter.connectToRedis(redis);
app.useWebSocketAdapter(redisIoAdapter);
}
return app;
}