开发者社区 > 云原生 > Serverless > 正文

请问 nodejs12版本的http函数计算。本地和线上的请求转换怎么控制为一致的解析模式。 本地

请问 nodejs12版本的http函数计算。本地和线上的请求转换怎么控制为一致的解析模式。 本地是这样

提问5.png

线上是这样

提问6.png

这里log的数据,是直接从request的query中拿到的

代码是这样:

exports.handler = (req, resp, context) => { getRawBody(req, async (err, body) => { const bodyToString = body.toString(); try { if (err) throw new HttpResponseError(err.message, 406); const startTime = new Date(); console.info( ${req.method} ${req.path} Request with ${JSON.stringify({ body: bodyToString, query: req.queries, headers: req.headers, })} ); const data = bodyToString ? JSON.parse(bodyToString) : null; const result = await ServiceEntrance(req, data); resp.setStatusCode(200); const endTime = new Date(); console.info( ${req.method} ${req.path} Request success with ${JSON.stringify({ result, })}! It cost ${endTime - startTime}ms! ); return resp.send(JSON.stringify(result ? result : "")); } catch (error) { console.error( ${req.method} ${req.path} Request Error: ${ error.code ? error.code : 500 } with ${error.message} ); resp.setStatusCode(error.code ? error.code : 500); return resp.send(error.message); } }); };

展开
收起
云上静思 2022-11-07 15:50:26 1011 0
1 条回答
写回答
取消 提交回答
  • 参考这个: triggers:
    - name: log
    sourceArn: acs:log: : :project/
    type: log
    role: acs:ram:: :role/aliyunlogetlrole
    qualifier: LATEST
    config:
    sourceConfig:
    logstore: log
    jobConfig:
    maxRetryTime: 3
    triggerInterval: 60
    functionParameter: {}
    logConfig:
    project: test-data-abc-ss
    logstore: log2
    enable: false https://docs.serverless-devs.com/fc/yaml/triggers#log%E8%A7%A6%E5%8F%91%E5%99%A8

    此答案来自钉钉群“阿里函数计算官网"

    2022-11-07 19:09:23
    赞同 展开评论 打赏

快速交付实现商业价值。

相关产品

  • 函数计算
  • 相关电子书

    更多
    All in Serverless 阿里云核心产品全面升级 立即下载
    AIGC 浪潮之上,森马的 Serverless 实践之旅 立即下载
    阿里巴巴HTTP 2.0实践及无线通信协议的演进之路 立即下载

    相关镜像