I've got a server to which I need to make posts, get, etc. with HTTPClient. This host is example.com:8080
, for example. It's a tomcat with JSESSIONID
Java cookie.
When I'm developing, I set the withCredentials: true
on a interceptor for sending the cookies to the server. But, of course, I'm in localhost:4200
If I run the java server locally, i.e. at localhost:8080
, after I log in the java application I get the cookie and, running angular dev server in another browser tab, the withcredentials
feature is working fine, but now I can't run the java app on local, so I need to send my requests to example.com:8080
, so of course it's not working because de domain does not match.
I tried to set server
and local.server
in my hosts
file, but didn`t make the trick. I'm thinking about a kong api gateway or an nginx as reverse proxy, but seems to much complicated for what I want to do.
What is the best approach to make this to work?
Finally, I've made it with a really simple http proxy for node.js:
The library is on https://www.npmjs.com/package/http-proxy
This allows me to create a proxy on my localhost to go to
example.com
and also get rid of CORS problem!The code is as follows:
works like a charm!
For rookies, this can be set as
proxy.js
and execute with:So your
example.com:8080
will be proxied tolocalhost:5000
in this example.