【问题标题】:NestJs Body() is not populating with request information when coupled with serverless与无服务器结合时,NestJs Body() 未填充请求信息
【发布时间】:2019-04-24 21:33:06
【问题描述】:

当运行 SLS Offline 或 SLS Deploy 时,嵌套中的 body 装饰器没有被传递的对象填充。

我已经为任何感兴趣的人收集了一个小型 repo 来调查这个问题。

https://gitlab.com/claridgicus/nest-serverless-body-issue

SLS 离线输出

[Nest] 91880   - 2019-04-24 20:58   [ExceptionHandler] Map#toJSON isn't generic +5ms
TypeError: Map#toJSON isn't generic
    at String.toJSON (c:\Users\Claridgicus\AppData\Roaming\npm\node_modules\serverless\node_modules\core-js\modules\_collection-to-json.js:6:38)
    at Function.<anonymous> (c:\Users\Claridgicus\AppData\Roaming\npm\node_modules\serverless\node_modules\core-js\modules\_ctx.js:18:15)
    at JSON.stringify (<anonymous>)
    at Function.stringify [as default] (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\fast-safe-stringify\index.js:11:18)
    at ModuleTokenFactory.getDynamicMetadataToken (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\@nestjs\core\injector\module-token-factory.js:20:69)
    at ModuleTokenFactory.create (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\@nestjs\core\injector\module-token-factory.js:12:27)
    at ModuleCompiler.compile (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\@nestjs\core\injector\compiler.js:19:47)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
 1: std::vector<v8::CpuProfileDeoptFrame,std::allocator<v8::CpuProfileDeoptFrame> >::vector<v8::CpuProfileDeoptFrame,std::allocator<v8::CpuProfileDeoptFrame> >
 2: v8::internal::wasm::SignatureMap::Find
 3: v8::internal::Builtins::CallableFor
 4: v8::internal::Builtins::CallableFor
 5: v8::internal::Builtins::CallableFor
 6: 0000006B886843C1

【问题讨论】:

    标签: serverless nestjs


    【解决方案1】:

    所以

    经过反复检查 - 我仔细检查了传入请求的标头

    在收到来自美联储的 POST 请求时 - 仔细检查您是否设置了标头 - 与我不同的是,您可以节省几个小时 :)

        headers: {
            "Content-Type": "application/json"
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      相关资源
      最近更新 更多