Sunday, 4 March 2018

Cannot set cookie from nodeserver.

I have client a nodeServer and a remote server.I send a request to my local nodeserver from my clientaxios.post('http://localhost:3001/register', {email, password}) .then(res => { this.props.history.push('/user') }) And then inside the nodeServer I make a another request for the remote server and then I set a cookie in the callback. In the example below I am not using any response from remote server, I simply try to set a hard-coded cookie for test purpose.However, it does not set any cookie.var registerOptions = { url: 'https://remoteserver/register', method: 'POST', form: {} }; const registerCallback = (res, error, response, body) => { res.cookie('cookieName', 'cookieValue') } app.post("/register", (req, res) => { registerOptions.form = req.body; request(registerOptions, (error, response, body) => registerCallback(res, error, response, body)) }) Also, my client does not directs to /user as a response from registerCallback , which is handled by .then(res => {this.props.history.push('/user')}) inside the axios request from client.If I simply send a response, such as res.send('hello') after res.cookie, it does navigate to /user page, but still no cookie.Am I having this problem due to the fact that my client is running on port 3000 and noderserver is on 3001 ?

Submitted March 04, 2018 at 08:01PM by oneevening

No comments:

Post a Comment