Nirvana Javascript : Serving From Another Webserver.

The XMLHTTP Request Object only allows requests to URLs with the same port and protocol as that of the XMLHTTP-hosting page.

See http://msdn.microsoft.com/en-us/library/ms537505.aspx#xdomain

Thus, any Nirvana webExpress libraries and code used to initiate a session must be served from the same port and protocol as the webExpress plugin.

It is, however, possible to take advantage of a subset of permissible "Cross Domain" scripting behaviours to distribute a webExpress application across more than one host.

At minimum, the end client must be able to:

  • request a single html file (to create a webExpress session), as well as the required nirvanaAsyncObjJSNotation.js file, from a Nirvana File Plugin running on hostA.somedomain.tld:portA
  • make requests to a webExpress Plugin configured on the same Nirvana server: hostA.somedomain.tld:portA

All other content may be hosted on another host and/or port in the same domain (e.g. Apache running on hostB.somedomain.tld:portB).

To accomplish this, the following application organization is required:

  • the XMLHTTP-hosting page served by the Nirvana File Plugin must explicitly set a JavaScript property (document.domain) to the value of the common parent domain, "somedomain.tld".
  • the main application page served by Apache must also set the this property to the same value (document.domain = "somedomain.tld").
  • the main application page served by Apache must contain an IFrame whose source URL is that of the XMLHTTP-hosting page served by the Nirvana File Plugin.
  • the Web Express plugin must be configured to deliver a suitable <script>document.domain = "somedomain.tld";</script> string in its InitJavascript parameter.

Please see our bundled sample zip file which contains the sample application re-organized in this manner.

Note that since the webExpress session object now exists within an IFrame embedded in the main page, rather than within the main page itself, any function calls that specify callback methods may need their parameter values modified to ensure that the browser can find and execute the appropriate callbacks. Since, in this example, we have chosen to implement the majority of callback methods in the Apache-served “main” page, rather than in the Nirvana File Plugin-served “webExpressFrame.html”, the names of such callback methods in webExpress-related function calls have been prefixed with “window.parent.”.

Further Notes:

Although the example in the bundled ZIP file assumes that lib/nirvanaAsyncObjJSNotation.js is also available on the Apache server, this is not strictly necessary. From the main application page, hosted on Apache, it is possible to refer to and manipulate webExpress objects that exist within the child webExpress frame and which are served from the Nirvana File Plugin (in this example, one might use code such as window.wx.mySession or window.wx.nChannelAttributes).

Please note that when you specify JavaScript code to initialise the document.domain property in the Nirvana webExpress Plugin, you will need to ensure that ALL pages that make use of webExpress also set document.domain (with the same value). Failure to do this will cause applications to fail with browser permission errors.

This technique will not circumvent browser restrictions on mixed protocols. Apache, Nirvana File Plugin, and Nirvana webExpress Plugin must therefore be using the same protocol (ie all HTTP or all HTTPS).

Share this page with others:
Tell Your Tweets Facebook It! Add to Delicious Reddit! Digg It! Stumble Upon Add to Your Faves Mixx it
Follow Us:
Keep up with my-Channels on Twitter Become a fan on Facebook LinkedIn Profile Recent Highlights RSS Feed