-
Notifications
You must be signed in to change notification settings - Fork 65
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" appearing on every route despite the API routes working fine. #30
Comments
import connect from "next-connect"
import common from "../../../middleware/common/"
import keys from "../../../config/keys"
const handler = connect()
handler.use(common)
handler.post((req, res) => {
return res.status(200).send(keys.googleMapsKey)
})
export default (req, res) => handler.apply(req, res) Hi @drkgrntt, can you try doing this instead? |
It worked with |
This seems to work! In the readme, |
@drkgrntt I did not include this because it was not the case until #9999. See this comment
Howevere, it is just a harmless warning and should not cause any actual error in production as long as we handle every thing right in creating the middleware |
Great! Thank you for the quick responses. |
The .apply fix mentioned doesn't handle errors and leads to requests hanging. const router = nextConnect()
router.post(function (req, res) { res.end('ok') })
export default function (req, res) { return router.apply(req, res) } Maybe a method could be added that basically does this connect.apply = function apply(req, res) {
return new Promise((resolve) => this.handle(req, res, function (err) {
if (err) onError(err, req, res)
else onNoMatch(req, res)
resolve()
}))
} |
@throwarray Thanks, will be handled in #38. |
The next version will always return a promise so we do not need to use |
I recently switched from an Express server to NextJS's API pages, and I love the way this repo helps with that, so thank you!
That said, all of my API routes are logging "API resolved without sending a response". This issue was posted 3 days ago in nextjs's issues and was closed the next day with this comment being the solution to it. I was wondering if the solution could be implemented into this repo. It looks like the OP was using async/await and the comment that solved the problem recommended returning a Promise instead. In my particular case, all my my routes are printing the message, regardless of if they are asynchronous or not. One example is the following:
It's possible my problem lies elsewhere, but since all of my routes are going through next-connect, I figured this might be something to be looked at within the repo.
The text was updated successfully, but these errors were encountered: