2

Problem: I have many web-services running under the same domain name which need to share a cookie. The front end is developed in AngularJS. When testing locally, the services run on localhost at different ports such as localhost:8181, localhost:8182, etc. In prodoction, this will look like www.mydomain.com/a/..., and www.mydomain.com/b/... Although I do not specify a port in my cookie, the cookies are not being shared across ports during local development. Any ideas?

AFrieze
  • 844
  • 1
  • 10
  • 26

2 Answers2

1

I was struggling with that problem too. You should run all your services on the same domain but under different paths in order to share cookies between them.

The only solution I could find was to use a NGINX reverse proxy. So you can make requests to http://localhost and http://localhost/back and NGINX redirects to http://localhost:3000 and http://localhost:5000 whatever port your applications are running on, and the cookies will work.

In this gist I share a basic example of how to run with docker compose an NGINX server and its necessary basic configuration.

https://gist.github.com/hugojavier667/c6033b74305fb547ed74625f0bb44dcb

You can add as many routes as services you have.

0

I believe that it is impossible to share cookies with different domains, this is a security measure that the browser is putting in place.

And a different port would count as a different domain, as far as I know.

Refer to this question: Sharing cookies across different domains and different applications (classic ASP and ASP.NET)

Community
  • 1
  • 1
Benjadahl
  • 80
  • 1
  • 10
  • Yes, I suspect I am running afoul of the cross origins policy. That said, in production the services will all run under the same domain name which should work fine...at least to my understanding. There must be a way which people develop and test such applications locally. – AFrieze Jul 01 '16 at 15:48
  • 1
    Is it possible that you could make the different services run undder a different path of the server? If you are using localhost:5000 Like so: localhost:5000/service1/ localhost:5000/service2/ I believe they could share cookies, but I am not entirely sure. – Benjadahl Jul 01 '16 at 15:49
  • That might work. Thank you for the idea, it's definitely worth investigating although I'm still hoping for another solution. – AFrieze Jul 01 '16 at 16:00