I looked over the previous postings but they did not seem to match my issue. I am only using the next.js package and the integrated api pages. Mongoose is what I am using to make my schemas. I keep getting the above error only for my post calls. Any ideas what is going wrong here?
import dbConnect from "../../../utils/dbConnect";
import Employee from "../../../models/Employee";
dbConnect();
export default async (req, res) => {
const { method } = req;
switch (method) {
case "POST":
await Employee.create(req.body, function (err, data) {
if (err) {
res.status(500).json({
success: false,
data: err,
});
} else {
res.status(201).json({
success: true,
data: data,
});
}
});
break;
default:
res.status(405).json({
success: false,
});
}
};
API resolved without sending a response for /api/users/create, this may result in stalled requests. NEXTJS – JavaScript API resolved without sending a response for /api/users/create, this may result in stalled requests.
API resolved without sending a response for /api/trades, this may result in stalled requests. If you're using an externalResolver (such as Express), nextjs can't detect that the API response has been send. At the bottom of #10439 (comment) @timneutkens explains how you can disable the warning if that is indeed the case.
API resolved without sending a response for /api/users/create, this may result in stalled requests. In the else block of if statement res.end () must be called. To make API response clearer, consider using 405 status code instead of 500 in this case. 405 means method is not allowed (see here ).
Any file inside the pages/api is dealt with as an API endpoint, which the client-side can access. Here is an example API route that fetches an API from RapidAPI Hub. As you can see, we need some way to send the response and error (if any) to the client-side. This is where the Response Helpers come into play.
This is a false warning because in the provided code you always return a response. It's just Next.js doesn't know it.
If you are sure that you return a response in every single case, you can disable warnings for unresolved requests.
/pages/api/your_endpoint.js
export const config = {
api: {
externalResolver: true,
},
}
Custom Config For API Routes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With