I was used to do the following in some of my express
routes.
return res.sendStatus(200);
But the res
object from NextApiHandlerType
does not allow that method.
What would be the equivalent, in this case?
import { NextApiHandler } from "next";
const handler: NextApiHandler = async (req, res) => {
// DO STUFF
return res.??? // WHAT SHOULD I PUT HERE TO RETURN THE status CODE WITH THE STANDARD CODE MSG ?
};
I'm currently doing this, but it seems redundant.
return res.status(200).send("Ok");
From: http://expressjs.com/en/api.html
To anyone seeing this now, I was wondering the same thing. The docs aren't 100% clear IMO. This sends a status code and closes out the request.
res.status(200).end();
AFAIK, this is currently not possible inside a Next.js serverless function. I'm using "next": "10.1.3"
.
The closest alternative is, indeed:
return res.status(200).send("Ok");
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