首页 > 解决方案 > Lambda 在请求正文中返回标头

问题描述

我正在使用无服务器在 lambda 中部署我的 express js 应用程序。奇怪的是,一些 api 在响应正文中返回标头,我不确定为什么会这样。这是我的无服务器 YAML 文件:

org: test
app: test-api
# serverless.yml
service: test-api

package:
  exclude:
   #- node_modules/**
   - __tests__/**

provider:
    name: aws
    runtime: nodejs10.x
    region: us-east-1
    environment:
        SERVICE_NAME: ${self:service}

plugins:
  - serverless-domain-manager

custom:
  stage: ${opt:stage, dev}
  domains:
    prod: api.test.com
    dev: dev-api.test.com

  customDomain:
    basePath: "${self:provider.environment.SERVICE_NAME}"
    domainName: ${self:custom.domains.${self:custom.stage}}
    stage: "${self:custom.stage}"
    createRoute53Record: true

functions:
  test-api:
    handler: build/app.handler
    environment:
        stage: ${self:custom.stage}
    events:
      - http:
          path: v1/s
          method: GET
          cors: true
      - http:
          path: v1/sc
          method: GET
          cors: true
      - http:
          path: v1/s/{s}
          method: GET
          cors: true
      - http:
          path: v1/cs
          method: POST
          cors: true
      - http:
          path: v1/s
          method: POST
          cors: true
      - http:
          path: v1/s/{s}
          method: DELETE
          cors: true
      - http:
          path: v1/s/{s}
          method: PUT
          cors: true

这是响应的样子:

curl -d '{"c":"test"}' -H "Content-Type: application/json" -X POST https://dev-api.test.com/test-api/v1/cs

HTTP/1.1 200 Not Modified
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: sessionId
Vary: Origin
Content-Type: application/json; charset=utf-8
Content-Length: 55
ETag: W/"37-vmzwGqI9Wb8ACGS7qhhE3/JBqt4"
Date: Fri, 24 Apr 2020 12:30:41 GMT
Connection: keep-alive

{"rsp":{"msg":{"s":[],"c":{}},"err":null}

知道它是无服务器 yaml 还是其他配置?

标签: expresscurlaws-lambdaserverless-framework

解决方案


我能够解决这个问题,联系了无服务器支持,他们说有一个错误,现在它已经修复了。只需要更新无服务器就解决了!


推荐阅读