Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Guidance needed - how to store request context? #111

Open
magicmark opened this issue Mar 14, 2018 · 5 comments
Open

Guidance needed - how to store request context? #111

magicmark opened this issue Mar 14, 2018 · 5 comments

Comments

@magicmark
Copy link
Contributor

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!

@magicmark
Copy link
Contributor Author

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

@ljharb
Copy link
Collaborator

ljharb commented Mar 14, 2018

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

@magicmark
Copy link
Contributor Author

Oh that sounds better, yea! @ljharb++

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

@goatslacker
Copy link
Collaborator

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

@magicmark
Copy link
Contributor Author

Ah yeah, even better I suppose.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants