code update recorded at: 27/06/25 10:30:42
This commit is contained in:
commit
ca0e568f9e
|
|
@ -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