Giter Club home page Giter Club logo

nest.middleware's Introduction

미들웨어

미들웨어는 nest Request Lifecycle 에서 가장 실행되는 함수로서 Request 와 Response 에 대한 관리를 담당한다.

미들웨어 생성할땐 NestMiddleware 를 구현해주면 된다.

@Injectable()
export class GlobalMiddleware implements NestMiddleware {
  use(req: any, res: any, next: () => void) {
	  next();
  }
}

구현된 미들웨어를 적용하기 위해서는 모듈상에 적용하면된다.

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): any {

    // 전역 컨트롤러에 미들웨어 적용
    consumer.apply(GlobalMiddleware).forRoutes({
      path: '*',
      method: RequestMethod.ALL,
    });

    // 특정 컨트롤러에 미들웨어를 적용
    consumer.apply(LoggerMiddleware).forRoutes(ProfileController);
  }
}

nest.middleware's People

Watchers

kurokuma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.