In backbone.js, you have to set the rooturl of every model manually. Is there a way we can set this in a single location once and all models will use it?
For eg. api.site.com
will be the REST service, but for testing purpose, it may be at localhost:1000
I need to be able to change the root url of the service easily and not have them all over the place in the many models that exist in the application.
What I understand is :
You have several models: model1 and model2
The root URL can be either
http://api.site.com
orhttp://localhost:8080
depending on whether you are working locally or externally. And someday it could behttp://api.anothersite.com
I would do somthing like this then :
But be careful with this, you may forget to switch from one url to the other one when commiting. Better is to handle relative paths if they'd apply.