newtesting/handler.js

19 lines
749 B
JavaScript

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');
}
};