File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { CryptoModule } from '@douglasneuroinformatics/libnest/crypto' ;
22import { LoggingModule } from '@douglasneuroinformatics/libnest/logging' ;
33import { Module } from '@nestjs/common' ;
4+ import type { MiddlewareConsumer , NestModule } from '@nestjs/common' ;
45import { APP_GUARD } from '@nestjs/core' ;
56import { ThrottlerGuard , ThrottlerModule } from '@nestjs/throttler' ;
67
@@ -10,6 +11,7 @@ import { AuthenticationGuard } from './auth/guards/authentication.guard';
1011import { AuthorizationGuard } from './auth/guards/authorization.guard' ;
1112import { ConfigurationModule } from './configuration/configuration.module' ;
1213import { ConfigurationService } from './configuration/configuration.service' ;
14+ import { DelayMiddleware } from './core/middleware/delay.middleware' ;
1315import { GatewayModule } from './gateway/gateway.module' ;
1416import { GroupsModule } from './groups/groups.module' ;
1517import { InstrumentsModule } from './instruments/instruments.module' ;
@@ -93,4 +95,13 @@ import { UsersModule } from './users/users.module';
9395 }
9496 ]
9597} )
96- export class AppModule { }
98+ export class AppModule implements NestModule {
99+ constructor ( private readonly configurationService : ConfigurationService ) { }
100+
101+ configure ( consumer : MiddlewareConsumer ) {
102+ const isDev = this . configurationService . get ( 'NODE_ENV' ) === 'development' ;
103+ if ( isDev ) {
104+ consumer . apply ( DelayMiddleware ) . forRoutes ( '*' ) ;
105+ }
106+ }
107+ }
Original file line number Diff line number Diff line change 1+ import { Injectable , type NestMiddleware } from '@nestjs/common' ;
2+
3+ import { ConfigurationService } from '@/configuration/configuration.service' ;
4+
5+ @Injectable ( )
6+ export class DelayMiddleware implements NestMiddleware {
7+ constructor ( private readonly configurationService : ConfigurationService ) { }
8+
9+ use ( _req : any , _res : any , next : ( error ?: any ) => void ) {
10+ const responseDelay = this . configurationService . get ( 'API_RESPONSE_DELAY' ) ;
11+ if ( ! responseDelay ) {
12+ return next ( ) ;
13+ }
14+ setTimeout ( ( ) => {
15+ next ( ) ;
16+ } , responseDelay ) ;
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments