ScoPi
ScoPi

Reputation: 1183

How to pass deployment settings to application?

I am trying to deploy a Qooxdoo web application backed by CherryPy-hosted web services onto a server. However, I need to configure the client-side Qooxdoo application with the hostname of the server on which the application resides so that that the Ajax callbacks resolve to the right host. I have a feeling I can use the capabilities of the generate.py Qooxdoo script to generate client-side code with this appropriately set, but reading through the docs hasn't helped make it clear how yet. Anyone have any tips?

(FWIW, I know how I'd approach this using something like PHP and a different client-side framework like Echo 3--I'd have the index file be a PHP file that reads a local system configuration file prior to sending back client-side code. In this case, however, the generate.py file is a necessary part of the toolchain, so I can't see how to do it so simply.)

Upvotes: 0

Views: 173

Answers (2)

Stelios Joseph Karras
Stelios Joseph Karras

Reputation: 483

You can use qx.core.Enviroment class to add/get configuration for your project. The recommend way is only during compilation time, but there is a hack if you want to configure your application during run time.

Configuration during compilation time

If you want to configure the environment during compilation time see this.

In both cases after you add any environmental variable to your application, it can be accessed using the qx.core.Environment.get method.

On run time

WARNING this method isn't supported/documented from qooxdoo. Basically it's a hack

If you want to make available some environment configuration on run time you have to do this before qooxdoo loads. In order to this you could add some javascript into your webpage e.g.

window.qx = { };
window.qx.$$environment = {
 "myawsomeapp.hostname": "example.org",
};

This should be added somewhere in your page before the qooxdoo start loading otherwise it will not have the desirable effect. The advantage of this method is that you can push configuration to the client e.g. some api keys that may be different between instances of your application.

Upvotes: 1

johnspackman
johnspackman

Reputation: 1003

The easiest way will be to compose your AJAX URL on the fly from window.location; ideally, you would be able to use window.location.origin which for this StackOverflow website would be "https://stackoverflow.com" but there are issues with that on IE.

A cross platform solution is:

var urlRoot = window.location.protocol + "//" + 
  window.location.hostname + (window.location.port ? ':' +
  window.location.port: '');

This means your URL will always be correct, even if the server name changes (eg your on a test server instead of production).

See here for more details: https://tosbourn.com/a-fix-for-window-location-origin-in-internet-explorer/

Upvotes: 1

Related Questions