nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.32k stars 7.59k forks source link

when inject the response object using @Res(), the endpoint will become gateway timeout #1531

Closed ymchun closed 5 years ago

ymchun commented 5 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When any endpoints which injected the response object using @Res() decorator, the handler didn't called at all. From the following code example, the console has nothing printed out.

Expected behavior

The handler should be called and the console should print out debug

Minimal reproduction of the problem with instructions

import { Controller, Get, Res } from '@nestjs/common';
import { Response } from 'express';

@Controller('whatever')
export class WhateverController {

    @Get()
    public async index(@Res() res: Response): Promise<void> {
        console.log('debug');
        // do some async stuff
    }
}

👆👆👆👆👆 this doesn't work 👆👆👆👆👆

👇👇👇👇👇 this works 👇👇👇👇👇

import { Controller, Get } from '@nestjs/common';

@Controller('whatever')
export class WhateverController {

    @Get()
    public async index(): Promise<void> {
        console.log('debug');
        // do some async stuff
    }
}

Environment


Nest version: 5.7.0


For Tooling issues:
- Node version: 10.7  
- Platform: Mac  

Others:

my production environment is using `node:11.6-alpine` docker image and the OS is ubuntu 16.04
olmo commented 5 years ago

I have the same problem after updating to 5.7.0. The same code works fine in version 5.6.2.

kamilmysliwiec commented 5 years ago

image

https://docs.nestjs.com/controllers

olmo commented 5 years ago

Maybe I'm doing something wrong, this is my code:

    @Get(':id')
    async findOne(@Param('id') id, @Query() query, @Res() res) {
        const out = await this.invoiceService.findOne(id, query);
        if ('pdf' in query){
            res.setHeader('Content-Type', 'application/pdf');
        }
        res.send(out);
    }

Depending on the query i'm sending a json or a binary. That code was working fine in 5.6.2, but in 5.7.0 my service is not being called.

ymchun commented 5 years ago

@kamilmysliwiec the doc said if both approaches are used at the same time, @Res() approach will be used. But why the handler not called ?

And I follow https://docs.nestjs.com/controllers Library-specific approach example, still not working.

kamilmysliwiec commented 5 years ago

Could you share a small repository which reproduces your issue?

ymchun commented 5 years ago

During making the example code, it works after I removed all interceptors.

And I saw this https://docs.nestjs.com/interceptors

WARNING
The response mapping feature doesn't work with the library-specific response strategy (using the @Res() object directly is forbidden).

So, I think the root cause is interceptor didn't support library-specific response strategy, is there any way to skip global interceptors when using @Res() ?

ymchun commented 5 years ago

Why v5.6.2 global interceptor with @Res() works but v5.7.9 doesn't work?

kamilmysliwiec commented 5 years ago

Should be fixed in v5.7.1.

ymchun commented 5 years ago

@kamilmysliwiec thank you very much 🥳

olmo commented 5 years ago

This problem occurs again in the latest version of nestjs (6.0.1). I think it's the same problem, if I disable the interceptors It works again.

kamilmysliwiec commented 5 years ago

It was fixed here: https://github.com/nestjs/nest/issues/1738

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.