Skip to content

wbhob/nest-middlewares

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2d9f08f · Dec 25, 2024
Dec 25, 2024
Aug 14, 2018
Oct 27, 2023
Nov 24, 2017
Oct 27, 2023
Mar 27, 2019
Oct 27, 2023
Nov 24, 2017
Nov 24, 2017
Nov 24, 2017
Sep 30, 2019
May 3, 2019
Nov 23, 2017
Dec 25, 2024
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023
Nov 23, 2017

Repository files navigation

Coverage Status

Nest Middlewares

Add the most common Express middlewares to your Nest app with one line.

System Requirements

This packages requires the following:

  • Node.JS 18.0.0 or later
  • @nestjs/core and @nestjs/common 10.0.0 or later

Adding Middlewares

If you want to see a middleware added, I welcome contributions (or you can hire me). I've tried to make this project really easy to extend and hope we can build a resource for the Nest community together. See CONTRIBUTING.md for more information on how to create a new middleware. I'll merge and release it if it meets the contributing guidelines. Thank you for your contribution.

Usage

Take the name of your favorite Express middleware and prefix it with @nest-middlewares/.

$ npm install --save @nest-middlewares/helmet

In your module:

import { HelmetMiddleware } from '@nest-middlewares/helmet'; // (look around in the source code for the exact class name)

@Module(...)
export class MyModule {
    configure(consumer: MiddlewaresConsumer) {
        // IMPORTANT! Call Middleware.configure BEFORE using it for routes
        HelmetMiddleware.configure( /* options as per helmet docs */ )
        consumer.apply(HelmetMiddleware).forRoutes(
            /* your routes */
        );
    }
}

Currently supports:

  • Compression
  • Connect RID
  • Connect Timeout
  • Cookie Parser
  • Cookie Session
  • CORS
  • Csurf
  • Error Handler
  • Helmet
  • Method Override
  • Morgan
  • Response Time
  • Serve Favicon
  • Serve Index
  • Serve Static
  • VHost