code update recorded at: 19/12/24 11:09:03
This commit is contained in:
commit
23b9656946
|
|
@ -0,0 +1,19 @@
|
||||||
|
export const handler = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { num1, num2 } = req.body;
|
||||||
|
console.log(req);
|
||||||
|
// Validate the input
|
||||||
|
if (typeof num1 !== 'number' || typeof num2 !== 'number') {
|
||||||
|
return res.status(400).json({ error: 'Both num1 and num2 must be numbers.' });
|
||||||
|
}
|
||||||
|
const sum = num1 + num2;
|
||||||
|
console.log(sum);
|
||||||
|
// Send the result as a string since res.end expects a string or buffer
|
||||||
|
res.end(sum.toString());
|
||||||
|
} catch (error) {
|
||||||
|
// Handle errors
|
||||||
|
console.error('Error occurred:', error.message);
|
||||||
|
// Send an error response if needed
|
||||||
|
res.status(500).setHeader('Content-Type', 'text/plain').end('Internal Server Error');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user