skonves / express-http-context

Get and set request-scoped context anywhere
MIT License
299 stars 26 forks source link

Support browser compilation (with noop functions) #22

Closed willdurand closed 5 years ago

willdurand commented 5 years ago

Hi, thanks for your lib!

We'd like to use your lib in our project but we do server-side rendering and the codebase is shared between node and the browser. This lib obviously does not work in the browser (and it is not designed for that), but could we add some improvements to be able to compile it for the browser?

I have created a lib that does that: https://github.com/willdurand/universal-express-http-context, it requires your lib by default and provides a noop interface for the browser: https://github.com/willdurand/universal-express-http-context/blob/master/browser.js.

That allows us to use the lib in both contexts, even though only the server context really relies on the HTTP context and CLS.

How would you feel about merging those changes into your lib so that more people can benefit from that and I don't have to watch this project all the time to make sure we are up-to-date?

Thanks!

skonves commented 5 years ago

I'm glad you have found it useful 😄

I think that it would be a great idea to add a browser-safe API (even if it no-ops). I looked at the universal fork and it looks like you are just adding an alternate browser-safe module. That seems reasonable. Go ahead and create a PR so we can have a conversation about the specifics and then get the changes integrated. :+1: