-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
contact.ts
33 lines (27 loc) · 992 Bytes
/
contact.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Joi from 'joi';
import type { NextApiRequest, NextApiResponse } from 'next';
import { createRouter } from 'next-connect';
import { withValidation } from 'next-validations';
import { NextResponse } from 'next/server';
const schema = Joi.object({
dob: Joi.date().iso(),
email: Joi.string().email().required(),
name: Joi.string().required(),
});
const validate = withValidation({
schema,
mode: 'body',
});
const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(req.body);
};
const router = createRouter();
router.post(validate(), handler);
export default router.handler({
// @ts-expect-error │ Type '(err: unknown) => NextResponse<unknown>' is not assignable to type '(err: unknown, req: IncomingMessage, res: ServerResponse) => ValueOrPromise<void>'. Type 'NextR typescript (2322) [41, 3]
onError: (err) => {
return new NextResponse('Something broke!', {
status: (err as any)?.statusCode ?? 500,
});
},
});