I have an API server running on port AAAA and the JS frontend app (emberjs, using yeoman) running on port BBBB on the development machine. On the live server these ports will be the same. Unfortunately on the development machine I run into cross origin policy problems.

What can I do about this?

PS: Currently I solved this by starting Chrome using

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

and using an absolute root path http://localhost:8888/ in the JS api. But I'm not really a fan of hardcoded urls and special flags. If there is a better solution for either, please let me know!

有帮助吗?

解决方案

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

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

and only change it for local development.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top