问题描述
我的应用程序在 serverless
框架中,我使用 vtl
模板作为 lambda resolver
。我的应用程序堆栈是 AppSync
、Lambda
在 Node JS
运行时、Serverless
框架和 vtl
模板。
我想弄清楚如何将自定义 response headers
从我的 lambda 添加到客户端,并非常感谢任何输入。到目前为止,请在下面找到我的代码:
Lambda
const securityHeaders = {
"content-type": "application/json; charset=utf-8","x-content-type-options": "nosniff","cache-control": "no-store,no-cache,must-revalidate,proxy-revalidate",};
callback(null,{
statusCode: 200,headers: securityHeaders,body: JSON.stringify({
data,})
});
return;
无服务器 yml
functions:
getData:
handler: src/handler.getData
events:
- http:
path: getData
method: post
custom:
configValidationMode: off
appSync:
schema: ['graphql-schemas/data.graphql']
authenticationType: AMAZON_COGNITO_USER_POOLS
mappingTemplates:
- dataSource: GetData
type: Query
field: getData
request: "data-request.vtl"
response: "data-response.vtl"
data-response.vtl
## return the body
#if($ctx.result.statusCode == 200)
##if response is 200
$ctx.result.body
#else
##if response is not 200,append the response to error block.
$utils.appendError($ctx.result.body,"$ctx.result.statusCode")
#end
上面的代码在邮递员中给了我结果,但我无法在响应部分看到我的自定义标头。我想我缺少如何在响应 vtl 中包含标题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)