react-relay-network-layer icon indicating copy to clipboard operation
react-relay-network-layer copied to clipboard

How to pass data from express req object to the req received by middleware

Open ruslantalpa opened this issue 8 years ago • 3 comments

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

ruslantalpa avatar Jun 09 '17 09:06 ruslantalpa

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.

nodkz avatar Jun 10 '17 12:06 nodkz

so there's no way to set cookies???

Blackening999 avatar May 25 '18 16:05 Blackening999

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.

nodkz avatar May 25 '18 18:05 nodkz