hypernova icon indicating copy to clipboard operation
hypernova copied to clipboard

Guidance needed - how to store request context?

Open magicmark opened this issue 6 years ago • 5 comments

Hi @goatslacker!

So I have a logger set up inside an express middleware, logging various things about the request.

One bit of information I'd like to add to the logs is - did the request hit a cold cache or not?

I have access to this information inside of my application code - inside of getComponent. However there's no great way that I can currently think of to thread this information along to other parts of the express app.

I'm thinking one way to do this would be to expose the express request object to the context object passed into getComponent https://github.com/airbnb/hypernova/blob/477257daad82e04f24ce851a9b3d21625354c783/src/utils/BatchManager.js#L90

Or maybe there's just a better way to architect this?

Thanks!

magicmark avatar Mar 14 '18 21:03 magicmark

(Shoving arbitrary things on the request object is clearly not ideal. I still need to do some more thinking here, but that's probably an orthogonal problem)

magicmark avatar Mar 14 '18 21:03 magicmark

I usually stick things on the response object (and never mutate the request)

ljharb avatar Mar 14 '18 21:03 ljharb

Oh that sounds better, yea! @ljharb++

ok so same question, s/request/response/ ?

magicmark avatar Mar 14 '18 21:03 magicmark

Why don't we pass a reference to res.locals?

goatslacker avatar Mar 14 '18 23:03 goatslacker

Ah yeah, even better I suppose.

I'll update my PR. Thanks for the quick responses!

magicmark avatar Mar 14 '18 23:03 magicmark