Search code examples
ibm-connectionsibm-sbt

Disable use of a proxy in IBM Social Business ToolKit


I am running into a Access-Control-Allow-Origin error when I am trying to build an OpenSocial Gadget with IBM Social Business ToolKit for IBM Connections.

I have 3 servers participating in this gadget:

  • CONNECTIONS: The IBM Connections 4.0 Server that will be hosting the gadget
  • IBMSBT: A server hosting the Social Business Toolkit scripts and app
  • JESSE_API: My application server hosting the API that the gadget will be using

The gadget xml is loaded from JESSE_API by CONNECTIONS. The view for the gadget loads scripts and makes calls to JESSE_API. I would like to use the Social Business Toolkit for accessing parts of Connections so the gadget view is also loading those components from IBMSBT.

I am currently just prototyping this - I was able to make this work just using the Connections 4.0 API but would rather use the SBT libraries.

For getting started I just dropped in the "Get My Communities - Main Window" snippet into my gadget's view and included the following scripts:

<script type="text/javascript">
    var djConfig = {
        parseOnLoad: true
    };
</script>

<script src="//IBMSBT/sbt.dojo180/dojo/dojo.js"></script>
<script src="//IBMSBT/sbt.sample.web/library?ver=1.8.0"></script>

Reloading the gadget gives the following error in the console:

XMLHttpRequest cannot load http://IBMSBT/sbt.sample.web/service/proxy/connections/http/CONNECTIONS/communities/service/atom/communities/my?ps=5

Since my gadget was running on the CONNECTIONS server I should not need the proxy. I did not see an immediate way to disable the proxy for this endpoint so I just set a breakpoint in Endpoint.js before line 160 where the following code is executed:

if(this.proxy) {
    args.url = this.proxy.rewriteUrl(args.url,this.proxyPath);
}

When the breakpoint hits, I set this.proxy = null which causes the proxy to not be used and the community information to return correctly.

My question is should I be doing this differently or should a way be added to bypass the use of a proxy given the structure I am currently using?


Solution

  • Based on the information from Mark Wallace, I looked a bit closer at what the /library/ endpoint was doing.

    I was not able to make it quite work exactly with that code but the following works nicely:

    <script data-dojo-config="parseOnLoad:true"
            src="//IBMSBT/sbt.dojo180/dojo/dojo.js.uncompressed.js"></script>
    
    <script>
    if(typeof _sbt=='undefined' || window._sbt_bridge_compat){
        _sbt=0;
        dojo.registerModulePath('sbt','http://IBMSBT/sbt/js/sdk/sbt');
        dojo.registerModulePath('sbt/_bridge','http://IBMSBT/sbt/js/sdk/_bridges/dojo-amd');
        dojo.registerModulePath('sbt/dojo','http://IBMSBT/sbt/js/sdk/dojo');
        define('sbt/config',['sbt/Proxy','sbt/_bridge/Transport','sbt/authenticator/Basic','sbt/Endpoint'],function(Proxy,Transport,Basic,Endpoint){
            window.sbt = {};
            sbt.Properties={
                "sbtUrl":"http:\/\/IBMSBT\/sbt\/js\/sdk"
            };
            sbt.Endpoints={
                'connections':new Endpoint({
                    "baseUrl":"http:\/\/connectionsww.demos.ibm.com",
                    "transport":new Transport({}),
                    "authType":"basic",
                    "authenticator":new Basic({}),
                    "proxyPath":"connections"})
            };
            return sbt;
        });
    }
    </script>
    

    The contents of the script tag was basically the output from the /library/ endpoint. The sbt.Endpoints.connections definition originally included a defined proxy attribute which I removed.