【问题标题】:Why should I bind req and res to cls.Namespace?为什么要将 req 和 res 绑定到 cls.Namespace?
【发布时间】:2020-01-14 08:49:56
【问题描述】:

这是使用 cls-hooked 的常用方法。

我不知道为什么以后真的需要这样做。

return function clsifyMiddleware(req, res, next) {
        ns.bindEmitter(req);
        ns.bindEmitter(res);
}

【问题讨论】:

    标签: javascript node.js logging continuation-local-storage


    【解决方案1】:

    因为在异步错误的情况下,您可以拥有请求上下文。见https://blog.besson.co/nodejs_async_hooks_to_get_per_request_context/(async_hooks 是 cls-hooked 的潜在替代品)

    【讨论】:

      猜你喜欢
      • 2022-12-11
      • 2016-04-03
      • 2011-06-09
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 2012-11-20
      • 2016-10-14
      • 2012-12-02
      相关资源
      最近更新 更多