@poolsea-nestjs/middleware
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Middleware

NestJS Middleware Module for Lido Finance projects. Part of Lido NestJS Modules

Install

yarn add @poolsea-nestjs/middleware

Usage

Basic usage

// 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);
    });
  }
}

Async usage

// 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);
    });
  }
}

Package Sidebar

Install

npm i @poolsea-nestjs/middleware

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

9.45 kB

Total Files

12

Last publish

Collaborators

  • gomel-tdl1