airbnb / hypernova

A service for server-side rendering your JavaScript views

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Guidance needed - how to store request context?

magicmark opened this issue · 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

obj[token] = {

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

Thanks!

(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)

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

Oh that sounds better, yea! @ljharb++

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

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

Ah yeah, even better I suppose.

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