nodejs-buildpack-func-sample/index.js
2024-04-22 13:53:46 +05:30

21 lines
594 B
JavaScript

// Define the handler function
export const handler = async (event, context) => {
try {
// Prepare the response JSON
const responseJson = {
message: "Hello World",
};
// Set the response headers
context.setHeader("Content-Type", "application/json");
// Send the response JSON
context.end(JSON.stringify(responseJson));
} catch (error) {
// Handle errors
console.error(error);
// Send an error response if needed
context.statusCode = 500;
context.setHeader("Content-Type", "text/plain");
context.end("Internal Server Error");
}
};