refactor(backend): connect RequestLoggingMiddleware through DI
- AppModule implements NestModule with configure() for middleware - Remove manual middleware instantiation from main.ts - 120 tests pass, build succeeds
This commit is contained in:
parent
6e8efd2b80
commit
238836c850
@ -1,4 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { CacheModule } from './modules/cache/cache.module';
|
import { CacheModule } from './modules/cache/cache.module';
|
||||||
import { MoexClientModule } from './modules/moex-client/moex-client.module';
|
import { MoexClientModule } from './modules/moex-client/moex-client.module';
|
||||||
@ -11,6 +11,7 @@ import { PortfolioModule } from './modules/portfolio/portfolio.module';
|
|||||||
import { PrismaModule } from './modules/prisma/prisma.module';
|
import { PrismaModule } from './modules/prisma/prisma.module';
|
||||||
import { AuthModule } from './modules/auth/auth.module';
|
import { AuthModule } from './modules/auth/auth.module';
|
||||||
import { TBankModule } from './modules/tbank/tbank.module';
|
import { TBankModule } from './modules/tbank/tbank.module';
|
||||||
|
import { RequestLoggingMiddleware } from './common/middleware/request-logging.middleware';
|
||||||
import configuration from './config/configuration';
|
import configuration from './config/configuration';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@ -29,4 +30,8 @@ import configuration from './config/configuration';
|
|||||||
TBankModule,
|
TBankModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule implements NestModule {
|
||||||
|
configure(consumer: MiddlewareConsumer) {
|
||||||
|
consumer.apply(RequestLoggingMiddleware).forRoutes('*');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { AppModule } from './app.module';
|
|||||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||||
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
|
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
|
||||||
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
|
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
|
||||||
import { RequestLoggingMiddleware } from './common/middleware/request-logging.middleware';
|
|
||||||
import { ValidationPipe } from '@nestjs/common';
|
import { ValidationPipe } from '@nestjs/common';
|
||||||
import cookieParser from 'cookie-parser';
|
import cookieParser from 'cookie-parser';
|
||||||
|
|
||||||
@ -18,9 +17,6 @@ async function bootstrap() {
|
|||||||
app.useGlobalInterceptors(new TransformInterceptor());
|
app.useGlobalInterceptors(new TransformInterceptor());
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|
||||||
const reqLogMiddleware = new RequestLoggingMiddleware();
|
|
||||||
app.use(reqLogMiddleware.use.bind(reqLogMiddleware));
|
|
||||||
|
|
||||||
app.enableCors({ origin: true, credentials: true });
|
app.enableCors({ origin: true, credentials: true });
|
||||||
|
|
||||||
const config = new DocumentBuilder()
|
const config = new DocumentBuilder()
|
||||||
|
|||||||
@ -6,10 +6,10 @@ import configuration from '../../config/configuration';
|
|||||||
|
|
||||||
describe('HealthService', () => {
|
describe('HealthService', () => {
|
||||||
let service: HealthService;
|
let service: HealthService;
|
||||||
let prisma: Pick<PrismaService, '$queryRaw'>;
|
const prisma = { $queryRaw: vi.fn() } as any;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
prisma = { $queryRaw: vi.fn() };
|
vi.clearAllMocks();
|
||||||
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
imports: [ConfigModule.forRoot({ load: [configuration], isGlobal: true })],
|
imports: [ConfigModule.forRoot({ load: [configuration], isGlobal: true })],
|
||||||
|
|||||||
@ -39,10 +39,11 @@
|
|||||||
- [x] 4.6 Тесты: `health.service.spec.ts` (3 теста) + `envelope-contract.spec.ts` проверяет checks
|
- [x] 4.6 Тесты: `health.service.spec.ts` (3 теста) + `envelope-contract.spec.ts` проверяет checks
|
||||||
- [x] Все 120 тестов проходят
|
- [x] Все 120 тестов проходят
|
||||||
|
|
||||||
## Итерация 5: RequestLoggingMiddleware DI
|
## Итерация 5: RequestLoggingMiddleware DI ✅
|
||||||
|
|
||||||
- [ ] 5.1 Переписать подключение через `configure()` в `AppModule`
|
- [x] 5.1 `AppModule` implements `NestModule` с `configure()` → `consumer.apply(RequestLoggingMiddleware).forRoutes('*')`
|
||||||
- [ ] 5.2 Убрать `app.use()` из `main.ts`
|
- [x] 5.2 Убран `new RequestLoggingMiddleware()` и `app.use()` из `main.ts`
|
||||||
|
- [x] 120 тестов проходят, build успешен
|
||||||
|
|
||||||
## Итерация 6: MoexClientService split (отдельный эпик)
|
## Итерация 6: MoexClientService split (отдельный эпик)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user