No longer part of fastify module type, need to be imported directly from fastify-now
import { NowRequestHandler } from 'fastify-now';
also, must include request types in typescript:
export const POST: NowRequestHandler<{ Body: { name: string }; Params: { id: string } }> = async (
req,
rep,
) => {
if (req.body.name === 'Jon Doe') {
/**
* in async function, you can return undefined if you already sent a response
* then it won't try to send a response again with the returned value;
*/
rep.status(400).send({ message: 'Name can not be Jon Doe' });
return;
}
return { userId: req.params.id };
};
NowRequestHandler
No longer part of
fastify
module type, need to be imported directly fromfastify-now
also, must include request types in typescript: