I have build a REST Api in Node.js using Restify which works like a charm. One of the REST Endpoints, a GET, does some stuff and then returns result back to the caller with a Set-Cookie in the header.
When I run call the endpoint directly in my browser on http://127.0.0.1/theEnd
I receive a cookie, which I can also see in document.cookie
The cookie domain was set to 127.0.0.1
.
However, when I call the endpoint from an jquery Ajax function, on another domain: http://beauty.local, and of course set the cookiedomain to beauty.local, I do see the Set-Cookie line in the header:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://beauty.local
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Headers: X-Requested-With,content-type
Access-Control-Allow-Credentials: true
Set-Cookie: beauty-api=U2FsdGVkX18Wg3X2OOLlbC2zc62b7ibHEiQ+0MuR6jE6/lhdPUTD8ZxBEJJ1gcJ4qK/87SZ57xwHHl/cxkA1pfw3+wLQ1zMGpn1z10wd++ZyV4J+IevFPm71DbMu9qTD0Rmk7eQjSywVkRtBgKZPInX15X3WU28tO6KYtHSunEesxt4mAn4Kp5DpVWEsO2TG;expires=Sat, 31 May 2014 14:50:09 GMT;domain=beauty.local;
Content-Type: application/json
Content-Length: 76
Access-Control-Expose-Headers: api-version, content-length, content-md5, content-type, date, request-id, response-time
Date: Thu, 29 May 2014 14:50:09 GMT Connection: keep-alive
However, when I check my devtools in Chrome, I do not see the cookie under Resources/cookie/beauty.local and also I can't get it using document.cookie. I do see it as a response cookie under the network tab.
I am a bit puzzled, because it works when I call the endpoint directly on my localhost, but when I call it with ajax from another local domain, it doesn't.
What am I missing here.
Thanks in advance