Giter Club home page Giter Club logo

Comments (3)

kurtmilam avatar kurtmilam commented on July 17, 2024

A few suggestions:

  1. Make sure you set $.cors=true;
  2. If you're using jQuery Mobile, set $.mobile.allowCrossDomainPages = true; in your config on the `mobilinit' event.
  3. If you control the server, look into using Access-Control-Allow-Origin to allow xhr access to your app.

from backbone.dualstorage.

lucian1900 avatar lucian1900 commented on July 17, 2024

It already works without CORS on PhoneGap by whitelisting the server. We do control the server, but have little time to fix it atm. Thanks for the tips.

This issue is strictly about the URL models point to. I want to keep the host out of the url, but still allow connection to both origin and a different domain.

from backbone.dualstorage.

kurtmilam avatar kurtmilam commented on July 17, 2024

Before you publicized this repository, I was working on something similar that might be helpful.

  1. I created an ApiConfig module that contains a host attribute (3 actually, based on which environment the app is running in).
  2. I extended Models and Collections, adding two params - service and endpoint attributes (host could also be added here rather than in a config).
  3. I set Model.urlRoot and Collection.url to a function that builds the correct URL:
    apiConfig[environment].host + '/' + object.service + '/' + object.endpoint

This gives me a flexible way to dynamically build the Model.urlRoot and Collection.url. The setup could be fleshed out to cover more edge cases, but it works for my needs right now.

How this relates to dualSync. When creating a new store, dualSync could simply look for object.service and object.endpoint. If either or both are found, the key for the new store would be [object.service] + '/' + [object.endpoint] + '/' guid (square brackets represent optional values here). If neither are found, revert to object.url + '/' guid.

dualSync would still work for people who aren't interested in adding host, service or endpoint, since it would fall back to url, while still supporting those who want a little more granularity.

Another option is to pass the key/endpoint inside options, but I honestly don't like having to pack too much into options in order to have things work correctly.

from backbone.dualstorage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.