Access request context anywhere

后端 未结 2 2118
南笙
南笙 2021-02-13 00:48

I\'m using Express and I need to access some data that it is on the request (headers, cookies, etc) every time I use the log to debug and trace my app.

With other langu

2条回答
  •  温柔的废话
    2021-02-13 01:06

    Have a look at Continuation Local Storage, it implements something similar to thread context for asynchronous call chains: https://github.com/othiym23/node-continuation-local-storage

    Also there are efforts to build asynchronous local storage as a standardized feature into javascript itself, but they are still at a very early stage: TC39 Zone Proposal https://docs.google.com/presentation/d/1H3E2ToJ8VHgZS8eS6bRv-vg5OksObj5wv6gyzJJwOK0

提交回复
热议问题