Passthrough mode is a hybrid response handling approach in NestJS that allows manual interaction with the native response object while preserving the framework’s standard response handling for the rest of the request lifecycle.
Usage
Enable passthrough with @Res({ passthrough: true }):
@Get()
findAll(@Res({ passthrough: true }) res: Response) {
res.status(HttpStatus.OK); // Manual manipulation
return []; // Nest handles serialization and response
}Benefits
- Interact with native response (set cookies, headers based on conditions)
- Retain compatibility with NestJS features like Interceptors
- Avoid platform lock-in for most response handling
Use cases
- Setting cookies conditionally
- Manipulating specific headers while letting Nest handle the response body
- Mixing custom response logic with framework-provided features