ruby on rails - How set cookie sent from server to a client on a different port -


i have backend server (powered rails), apis used html5 frontend runs on node simple development server.

both on same host: machine.

when login frontend backend, rails sent me session cookie. can see in response headers, problem browsers not save it.

policies right, if serve same frontend directly rails app cookies set right.

the difference can see when frontend run on node server, runs on port 8080 , rails on port 3000. knew cookies not supposed port specific, missing happening here.

any thoughts? solutions?

(i need able keep setup way, have frontend served node , backend on rails on different ports)

you're correct cookies domain agnostic, , browser send same cookies myapp.local:3000 myapp.local:8080--except not through xmlhttprequest (a.k.a., ajax) when doing cors.

make sure set withcredentials true on xmlhttprequest object. (https://developer.mozilla.org/en-us/docs/web/api/xmlhttprequest/withcredentials).

also, since tagged webpack-dev-server in question, might interested in proxying requests rails api through webpack-dev-server avoid cors issues in first place. done in weback.config:

proxy: {   '/some/path': {     target: 'https://other-server.example.com',     secure: false   } } 

see: https://webpack.github.io/docs/webpack-dev-server.html#proxy


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -