mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix(server): move global filters, pipes, and interceptors to AppModule
This commit is contained in:
@@ -4,10 +4,6 @@ import { ClsMiddleware } from 'nestjs-cls';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import './utils/moment-mysql';
|
import './utils/moment-mysql';
|
||||||
import { AppModule } from './modules/App/App.module';
|
import { AppModule } from './modules/App/App.module';
|
||||||
import { ServiceErrorFilter } from './common/filters/service-error.filter';
|
|
||||||
import { ModelHasRelationsFilter } from './common/filters/model-has-relations.filter';
|
|
||||||
import { ValidationPipe } from './common/pipes/ClassValidation.pipe';
|
|
||||||
import { ToJsonInterceptor } from './common/interceptors/to-json.interceptor';
|
|
||||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||||
|
|
||||||
global.__public_dirname = path.join(__dirname, '..', 'public');
|
global.__public_dirname = path.join(__dirname, '..', 'public');
|
||||||
@@ -25,11 +21,6 @@ async function bootstrap() {
|
|||||||
// create and mount the middleware manually here
|
// create and mount the middleware manually here
|
||||||
app.use(new ClsMiddleware({}).use);
|
app.use(new ClsMiddleware({}).use);
|
||||||
|
|
||||||
app.useGlobalInterceptors(new ToJsonInterceptor());
|
|
||||||
|
|
||||||
// use the validation pipe globally
|
|
||||||
app.useGlobalPipes(new ValidationPipe());
|
|
||||||
|
|
||||||
const config = new DocumentBuilder()
|
const config = new DocumentBuilder()
|
||||||
.setTitle('Bigcapital')
|
.setTitle('Bigcapital')
|
||||||
.setDescription('Financial accounting software')
|
.setDescription('Financial accounting software')
|
||||||
@@ -39,9 +30,6 @@ async function bootstrap() {
|
|||||||
const documentFactory = () => SwaggerModule.createDocument(app, config);
|
const documentFactory = () => SwaggerModule.createDocument(app, config);
|
||||||
SwaggerModule.setup('swagger', app, documentFactory);
|
SwaggerModule.setup('swagger', app, documentFactory);
|
||||||
|
|
||||||
app.useGlobalFilters(new ServiceErrorFilter());
|
|
||||||
app.useGlobalFilters(new ModelHasRelationsFilter());
|
|
||||||
|
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
|
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||||
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
|
import { APP_GUARD, APP_INTERCEPTOR, APP_PIPE, APP_FILTER } from '@nestjs/core';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||||
import { RedisModule } from '@liaoliaots/nestjs-redis';
|
import { RedisModule } from '@liaoliaots/nestjs-redis';
|
||||||
@@ -36,6 +36,10 @@ import { PdfTemplatesModule } from '../PdfTemplate/PdfTemplates.module';
|
|||||||
import { BranchesModule } from '../Branches/Branches.module';
|
import { BranchesModule } from '../Branches/Branches.module';
|
||||||
import { WarehousesModule } from '../Warehouses/Warehouses.module';
|
import { WarehousesModule } from '../Warehouses/Warehouses.module';
|
||||||
import { SerializeInterceptor } from '@/common/interceptors/serialize.interceptor';
|
import { SerializeInterceptor } from '@/common/interceptors/serialize.interceptor';
|
||||||
|
import { ValidationPipe } from '@/common/pipes/ClassValidation.pipe';
|
||||||
|
import { ToJsonInterceptor } from '@/common/interceptors/to-json.interceptor';
|
||||||
|
import { ServiceErrorFilter } from '@/common/filters/service-error.filter';
|
||||||
|
import { ModelHasRelationsFilter } from '@/common/filters/model-has-relations.filter';
|
||||||
import { ChromiumlyTenancyModule } from '../ChromiumlyTenancy/ChromiumlyTenancy.module';
|
import { ChromiumlyTenancyModule } from '../ChromiumlyTenancy/ChromiumlyTenancy.module';
|
||||||
import { CustomersModule } from '../Customers/Customers.module';
|
import { CustomersModule } from '../Customers/Customers.module';
|
||||||
import { VendorsModule } from '../Vendors/Vendors.module';
|
import { VendorsModule } from '../Vendors/Vendors.module';
|
||||||
@@ -234,10 +238,18 @@ import { AppThrottleModule } from './AppThrottle.module';
|
|||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [
|
providers: [
|
||||||
|
{
|
||||||
|
provide: APP_PIPE,
|
||||||
|
useClass: ValidationPipe,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: APP_GUARD,
|
provide: APP_GUARD,
|
||||||
useClass: ThrottlerGuard,
|
useClass: ThrottlerGuard,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: APP_INTERCEPTOR,
|
||||||
|
useClass: ToJsonInterceptor,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: APP_INTERCEPTOR,
|
provide: APP_INTERCEPTOR,
|
||||||
useClass: SerializeInterceptor,
|
useClass: SerializeInterceptor,
|
||||||
@@ -250,6 +262,14 @@ import { AppThrottleModule } from './AppThrottle.module';
|
|||||||
provide: APP_INTERCEPTOR,
|
provide: APP_INTERCEPTOR,
|
||||||
useClass: ExcludeNullInterceptor,
|
useClass: ExcludeNullInterceptor,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: APP_FILTER,
|
||||||
|
useClass: ServiceErrorFilter,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: APP_FILTER,
|
||||||
|
useClass: ModelHasRelationsFilter,
|
||||||
|
},
|
||||||
AppService,
|
AppService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user