From 23b965694632115ad3bcb61c073dfc7d8622c109 Mon Sep 17 00:00:00 2001 From: Abhishek Test Tiwari Date: Thu, 19 Dec 2024 11:09:03 +0000 Subject: [PATCH] code update recorded at: 19/12/24 11:09:03 --- handler.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 handler.js diff --git a/handler.js b/handler.js new file mode 100644 index 0000000..91c5c01 --- /dev/null +++ b/handler.js @@ -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'); + } +}; \ No newline at end of file