Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"API resolved without sending a response" false positive #10589

Closed
Janpot opened this issue Feb 19, 2020 · 3 comments
Closed

"API resolved without sending a response" false positive #10589

Janpot opened this issue Feb 19, 2020 · 3 comments

Comments

@Janpot
Copy link
Contributor

Janpot commented Feb 19, 2020

Bug report

Describe the bug

next api route logs

API resolved without sending a response for /graphql, this may result in stalled requests.

even though it sends a response;

To Reproduce

Set up a route like:

// /api/graphql.ts
import { createProxyMiddleware } from 'http-proxy-middleware';

export const config = {
  api: {
    bodyParser: false
  }
};

export default createProxyMiddleware({
  target: process.env.API_ENDPOINT,
  pathRewrite: { '^/api': '' }
});

And call it from the browser

Expected behavior

No unnecessary warning messages

System information

  • Version of Next.js: 9.2.2
@jamesmosier
Copy link
Contributor

Is this answer perhaps helpful? #10439 (comment)

"[Next] can't detect you are still doing work in the API unless you return a promise and wait to resolve it until after the callback is fired"

@Janpot
Copy link
Contributor Author

Janpot commented Feb 19, 2020

If I forget to send a response, I will notice soon enough because my API wouldn't do anything. No need for a log message, especially not if it can't be correctly calculated when it should apply. Maybe a better heuristic would be to check whether

  1. the handler returns a promise
  2. that promise resolves with something else then undefined

and then log something like It seems like you try to return a value from an API handler, but you should use "res.send" instead

PabloSzx added a commit to PabloSzx/next.js that referenced this issue May 7, 2020
This flag is useful when you are using an external API resolver like express when defining an API route, since the native functionality doesn't realize that the API actually sent a response.

A very simple use case example https://github.com/PabloSzx/next-external-api-resolver-example

fixes vercel#10589
rokinsky pushed a commit to rokinsky/next.js that referenced this issue Jul 11, 2020
* Add flag to disable API warning

This flag is useful when you are using an external API resolver like express when defining an API route, since the native functionality doesn't realize that the API actually sent a response.

A very simple use case example https://github.com/PabloSzx/next-external-api-resolver-example

fixes vercel#10589

* Update api-middlewares.md

Co-authored-by: Tim Neutkens <[email protected]>
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants