react-relay-network-layer
react-relay-network-layer copied to clipboard
How to pass data from express req object to the req received by middleware
In case of server side rendering, i want to forward a particular header (Cookie) from the express request to the (fetch) req object (the one received by middleware). How can one do that? I don't think i can have the middleware function accessing some global var (race conditions).
Thanks
Tricky question.
As you said, global var is the wrong solution. Don't use it for SSR.
I suppose that you should create network layer for every request. There is now way to pass request context to react-relay-network-layer.
I have not ready solution/example yet. So if you or somebody else make it working, please drop here an example for further googlers. Thanks.
so there's no way to set cookies???
Cookies are set by browser automatically. Network Layer should not set cookies, this is not its task.
So if you don't have cookies in the browser after fetch, then you incorrectly prepared your server.
Also take a look on fetch spec, it has not only same-origin, may be in your case need to use other policy.