I need to decouple front-end and back-end. I am using Rails for back-end and Backbone for front-end.
After a couple days of trial and error I was able to setup CORS on the server. All thanks to this module:
https://github.com/yaoweibin/nginx_cross_origin_module
Now I found out that Backbone does not support cross-domain calls out of the box.
I wonder what is the best way to decouple Backbone from back-end?
I see two solutions:
1) Write paths in Backbone models / collections that will point to the server, so I will get for example:
class App.Collections.Plots extends Backbone.Collection
model: App.Models.Plot
url: 'http://www.app.com/api/plots'
This will mean that I will have to also patch Backbone methods to support cross-domain.
2) Setup the rails-side of front-end part in such a way, that Rails, not Backone will be making cross-domain calls to the server.. This seems strange, because Backbone was supposed to make decoupling easier and now I will be kind of falling back to rails solutions.