Reputation:
I'm using expressjs library. It works on localhost:8000 as a server and i'm showing static pages with it. My application works on localhost:4200. I tried to use same cookie or localStorage on different pages of ports but it didn't work. How can i achieve this?
Upvotes: 0
Views: 1611
Reputation: 879
When you're working on different ports, if the cookies have the 'SameSite' attribute set to 'Host Only' and the domain set to 'localhost', they will be visible/accessible from both domains regardless of the port number.
As @codingmaster says, if it's different domains, you will have to implement cors management for different domains..
But since you own both applications, during production, one can be on the main domain while the other on a subdomain, then you'll have to set the domain attribute of the cookie to your domain, e.g: example.com
and the SameSite attribute can remain HostOnly
and the cookies will be accessible
Upvotes: 0
Reputation: 27
You can do this by calling the routes on localhost:8000 in your main application only, and since it is working on two different ports you may run to error due to Cors policy and for that you may look up to these answers. cors enable
Upvotes: 1
Reputation: 257
What I think you are trying to do here is have the cookie/local storage shared between two locations.
Hope this helps in some way.
Upvotes: 0