nodejs-dockerfile-func-sample/index.js
2024-04-26 07:18:36 +00:00

23 lines
618 B
JavaScript

// Define the handler function
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");
}
};
module.exports = { handler };