Im trying to create a javascript frontend whom should communicate with my rails backend. I figured installing Middleman would solve the annoying errors:

XMLHttpRequest cannot load http://localhost:3000/groups.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4567' is therefore not allowed access. 

Unfortunately it doesn't. I'm assuming because they're not on the same ports.

Is there a 'quick' fix for this; Or should I just add headers to my Rails project to avoid getting the XSS errors?

有帮助吗?

解决方案

Installing Rack-Cors on your Rails backend is your best bet to resolving your 'Access-Control-Allow-Origin' errors.

Running on the same ports wouldn't solve this straight out the bag as its a security constraint of cors and Middleman would'nt either.

Put simply to access groups.json you will need some form of Cors Headers present on the server

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