I have two node.js (express) applications running on two different ports. One runs on localhost:3000
, and the other runs on localhost:4000
. An application on port 3000
has the following cookie configuration:
app.use(express.cookieParser()) app.use(express.session({ key: settings.session.key, secret: settings.session.secret, cookie: settings.session.cookie, fingerprint: function () { return '' }, store: new MemoryStore() }))
And another application (on port 4000
) has:
app.use(express.cookieParser()) app.use(express.session({ key: settings.session.key, secret: settings.session.secret, cookie: settings.session.cookie, fingerprint: function() { return '' }, store: new MongoSessionStore({ db: db }) }))
They both use the same session configuration object (the only difference is that one is stored in MongoDB and the other in memory.
I set this cookie localhost:3000
:
res.cookie('mycookie', 'bar', { domain: 'localhost:4000' })
And then I POST (with jquery.ajax) to the route on localhost:4000
, but mycookie
does not.
Note. I have CORS configured on localhost:4000
to accept the start of localhost:3000
, and when I post to jQuery, I use xhrFields: { withCredentials: true }
.
So my question is how to properly configure applications to set cookies on each other? :)