Search code examples
javascriptbackbone.js

Relative URL in backbone model , to a port different form that in browser url


I am doing a project in javascript and use backbonejs for structuring. While using relative path in backbone model, the request is send to host:port used in browser url by default (here http://localhost:9090) . But I need to send request to my application server with port localhost:8080 . We can't use same port for client and server. So how can we handle this?

I have a json in client side specifying the root url:

data.json

{data:[{"urlRoot": "http:localhost:8080"}]}


Solution

  • Use model urlRoot http://backbonejs.org/#Model-urlRoot

    Or do specifically set http://localhost:8080/ as root in your model url (no relative path so you should keep this root information in some conf module so you can change it easily for all model when going into production).

    You could also store the root url in model prototype instead of conf module