NODE JS- EXPRESS: Unable to retrieve value from HTTP Context for POST and PUT requests while it works for GET

前端 未结 2 2103
-上瘾入骨i
-上瘾入骨i 2021-01-01 01:53

In Node.js and Express framework, I am unable to retrieve value from HTTP Context for POST and PUT requests while it works for GET. I am using httpContext to set a unique re

2条回答
  •  -上瘾入骨i
    2021-01-01 02:22

    I am having the same issue. Attempted the bindEmitter solution above and that did not work.

    After a few trail and errors REF#1 removing the 'Content-Type': 'application/json' header from my clients POST invocation allowed values in the context to be set/retained.

    This led me to suspect there was an issue with how the body-parser(v1.19.0) middleware and express-http-context(v1.2.3) interacts.

    When I reversed the order of the middleware such that body-parser comes before express-http-context httpContext was working as expected (without having to do REF#1 ) E.g:

    app.use(bodyParser.json()); //must come before
    app.use(httpContext.middleware);
    

提交回复
热议问题