0

We have backbone.js application that is using rest API. With every request user/pass should be send to the API. This is how we send the request:

`Backbone.BasicAuth.set(tempUser, tempPass);

    this.fetch({
         error: function(){
            // code
         },
        success:function(model, response){              
            // code                 
        }} );`

This was not working for IE 8/9 so we made node.js server and by using the node-http-proxy module we made proxy server that will intercept all the requests.

This is the node proxy server:

`var httpProxy = require('http-proxy');
 var options = {'target': {
     'host': 'test.someserver.com',
     'port': 8800
 }};

 httpProxy.createServer(function(req, res, proxy) {
     req.headers.host = 'test.someserver.com';
     proxy.proxyRequest(req, res, options);
 }).listen('8080');`

Our problem now is to send the user/pass to the node proxy server, we know that XDomainRequest does not support custom headers and we don't like to send the user/pass as query string (it is not secure).

Is there a way that user/pass can be send to the node proxy server from IE 8/9?

onetwo12
  • 2,359
  • 5
  • 23
  • 34

1 Answers1

1

Yes, I actually wrote a library to do just this.

https://github.com/victorquinn/Backbone.CrossDomain

It serves as a drop-in replacement for Backbone.sync() so any requests on IE7/8/9 will use IE's XDomainRequest object rather than XMLHttpRequest. Main idea is that you shouldn't have to change any of your model code but anything that defers to sync() will just work now when it previously wouldn't.

Feel free to contact me if you run into any problems using that library.

Another option is to put the proxy server on the same domain as your Backbone app (which would eliminate the need to use the XDomainRequest object) but it seems this is not an option here.

Victor Quinn
  • 1,107
  • 9
  • 12