Skip to content

How to add a custom pipe to server.ts? #2333

Answered by Romakita
VicAlar asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @VicAlar
Override ValidationPipe isn't encouraged because Ts.ED use @tsed/schema to map object, validate it and generate documentation.
Removing one of this point downgrade the Dev experience with Ts.ED.

Also any issue related to class-validator/Ts.ED won't be supported by us!

But the solution is the following

import {ValidationPipe} from "@tsed/platform-params";
import {JsonParameterStore} from "@tsed/schema";
import {OverrideProvider} from "@tsed/di";

@OverrideProvider(ValidationPipe)
export ClassValidatorPipe extends ValidationPipe {
  async transform(value: any, metadata: JsonParameterStore): Promise<any> {
   /// do something
  } 
}

Then in Server.ts add the following code:

im…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Romakita
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants