Advertisement
tonysamperi

021 - NestJS pipes

Aug 29th, 2022 (edited)
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.65 KB | Source Code | 0 0
  1. import {ValidationPipe} from "@nestjs/common";
  2.  
  3. const myPipe = new ValidationPipe({
  4.                     transform: true,
  5.                     whitelist: true
  6.                 });
  7.  
  8. // In app bootstrap (global for the entire app)
  9. app.useGlobalPipes(myPipe);
  10.  
  11. // In your module (global for that module)
  12. import {APP_PIPE} from "@nestjs/core";
  13. import {Module} from "@nestjs/common";
  14.  
  15. // ...
  16.  providers: [
  17.     {
  18.         provide: APP_PIPE,
  19.         useFactory: function () {
  20.             return myPipe
  21.         }
  22.     }
  23. ]
  24. // ...
  25.  
  26. // In your controllers (specific for that controller)
  27. @UsePipes(myPipe)
  28. @Controller()
  29. export class MyFooController {
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement