Interaction between JS server and API on different ports

I have an API server running on the AAAA port and a JS frontend application (emberjs using yoman) running on the BBBB port on the development machine. On a live server, these ports will be the same. Unfortunately, on the development machine, I ran into problems related to cross issues.

What can i do with this?

PS: I currently solved this by running Chrome using

 open -a Google\ Chrome --args --disable-web-security 

and using the absolute root path http://localhost:8888/ in the JS api. But I am not a fan of hard-coded URLs and special flags. If there is a better solution for any of them, please let me know!

+4
source share
1 answer

Besides using chrome with --disable-web-security , I used this snippet to avoid hardcoding the origin of the API

 var origin = location.origin.replace(/localhost:(\d+)/, 'localhost:8888'); 

and only change it for local development.

0
source

All Articles