NestJS Middleware Module for Lido Finance projects. Part of Lido NestJS Modules
yarn add @poolsea-nestjs/middleware
// Import
import { Module } from '@nestjs/common';
import { MiddlewareModule } from '@poolsea-nestjs/middleware';
import { MyService } from './my.service';
@Module({
imports: [
MiddlewareModule.forFeature({
middlewares: [
(next) => {
console.log(1);
next();
console.log(3);
},
],
}),
],
providers: [MyService],
exports: [MyService],
})
export class MyModule {}
// Usage
import { MiddlewareService } from '@poolsea-nestjs/middleware';
export class MyService {
constructor(private middlewareService: MiddlewareService) {}
async myMethod() {
return await this.middlewareService.go(() => {
console.log(2);
});
}
}
// Import
import { Module } from '@nestjs/common';
import { LoggerModule } from '@poolsea-nestjs/logger';
import { MiddlewareModule } from '@poolsea-nestjs/middleware';
import { MyService } from './my.service';
@Module({
imports: [
LoggerModule,
MiddlewareModule.forFeatureAsync({
imports: [LoggerModule],
async useFactory(loggerService: LoggerService) {
return {
middlewares: [
(next) => {
loggerService.log(1);
next();
},
],
};
},
inject: [LoggerService],
}),
],
providers: [MyService],
exports: [MyService],
})
export class MyModule {}
// Usage
import { MiddlewareService } from '@poolsea-nestjs/middleware';
export class MyService {
constructor(
private middlewareService: MiddlewareService,
private loggerService: LoggerService,
) {}
async myMethod() {
return await this.middlewareService.go(() => {
loggerService.log(2);
});
}
}