gpt4 book ai didi

node.js - 在 AWS Lambda for Node 模板中返回没有 API 网关的 HTML 响应

转载 作者:太空宇宙 更新时间:2023-11-03 23:16:13 24 4
gpt4 key购买 nike

我正在尝试使用 AWS Lambda 并使用无服务器 CLI 进行部署。我正在使用 aws-nodejs 模板生成我的项目文件夹。

这是 handler.js 代码:

'use strict';

module.exports.hello = async (event, context) => {
return {
statusCode: 200,
body: {
"message":
'Hello World! Today is '+new Date().toDateString()
}
};

// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};

我收到了 JSON 格式的成功响应。我正在尝试调整它以返回 HTML 响应。我应该为此更改内容类型吗?如果是这样怎么办?

我已经解决了以下问题:

还有其他一些。但它们都使用 Web 控制台和 API 网关,而我没有使用。

最佳答案

您只需要添加 html 的内容标题

return {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: '<p>Look ma, its sending html now</p>',
}

此外,这是 serverless examples in their github repo 之一.

关于node.js - 在 AWS Lambda for Node 模板中返回没有 API 网关的 HTML 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55156098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com