Answer the question
In order to leave comments, you need to log in
Can the server set a cookie to the server?
In general, I don’t understand what I’m going to ask about now, so if somewhere there is “well, stupidity in general”, tell me about it in order to direct it in the right direction.
What I need is this - when a client makes a request to the server, it passes a cookie. My prerender is happening on the client and before I reconsider the possibility of rendering an authorized user, I want to know if the server can set another server a cookie in the same way as a browser would?
That is, with nodejs, I will send requests to api on php, which needs those same cookies.
And to be extremely precise, the link is this - nginx (domain.ru) => express.js (localhost) => nginx(api.domain.ru) => php(localhost).
And if it is possible to do so, then how?
As requested, more details...
I have a nodejs server doing an isomorphic spa prerender using the data received from the php api. For authentication, I had to use a not quite standard approach with jwt + cookie. And in order to render the page for an authorized user on the node, you need to emulate the browser's work with cookies.
Answer the question
In order to leave comments, you need to log in
Let's define terms and concepts.
There are always two sides in interaction over the http protocol: the client (initiator of the request) and the server (forms the response to the request).
Cookies are simply http headers in the request and response that are exchanged between the client and the server .
Accordingly, the server does not care at all who initiated the request on the other side - the browser, nodejs, whatever. It just reads the request headers and returns a response with some other headers. Simply put, the server operates on the text of the request and generates the text of the response. What happens to the request before it gets to it and to the response after it is sent,the server doesn't care at all.
Thus, you just need to correctly process what the server sends on the client side (node) and form the correct requests, passing all the necessary headers there. This is what the browser automatically does for us, for example. It turns out that you need to emulate the behavior of the browser (I don’t know if node has any ready-made tools for this).
But all this is a literal answer to your question. If you describe your task in more detail, it may turn out that it can be solved more efficiently and correctly in other ways.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question