diff --git a/configs/client-default.js b/configs/client-default.js index d4b0a7b4..b967af8b 100644 --- a/configs/client-default.js +++ b/configs/client-default.js @@ -302,6 +302,9 @@ module.exports = function(options) { { packagePath: "plugins/c9.ide.language/language", workspaceDir: workspaceDir, + staticPrefix: options.packed + ? staticPrefix + : options.ideBaseUrl + "/uph" + staticPrefix, workerPrefix: options.CORSWorkerPrefix // "/static/standalone/worker" }, "plugins/c9.ide.language/keyhandler", diff --git a/node_modules/architect-build/build_support/mini_require.js b/node_modules/architect-build/build_support/mini_require.js index 756aded2..92370517 100644 --- a/node_modules/architect-build/build_support/mini_require.js +++ b/node_modules/architect-build/build_support/mini_require.js @@ -274,6 +274,9 @@ var config = require.config = function(cfg) { cfg.paths && Object.keys(cfg.paths).forEach(function(p) { config.paths[p] = cfg.paths[p]; }); + + if (cfg.baseUrlLoadBalancers) + config.baseUrlLoadBalancers = cfg.baseUrlLoadBalancers; }; config.packages = Object.create(null); config.paths = Object.create(null); @@ -322,9 +325,24 @@ require.toUrl = function(moduleName, ext, skipExt) { if (!absRe.test(url)) { url = (config.baseUrl || require.MODULE_LOAD_URL + "/") + url; } + if (url[0] === "/" && config.baseUrlLoadBalancers) { + var n = Math.abs(hashCode(url)) % config.baseUrlLoadBalancers.length; + url = config.baseUrlLoadBalancers[n] + url; + } return url; }; +function hashCode(string) { + var result = 0, i, chr, len; + if (string.length == 0) return result; + for (i = 0, len = string.length; i < len; i++) { + chr = string.charCodeAt(i); + result = ((result << 5) - result) + chr; + result |= 0; // Convert to 32bit integer + } + return result; +} + var loadScript = function(path, id, callback) { // TODO use importScripts for webworkers var head = document.head || document.documentElement; diff --git a/plugins/c9.static/unpacked_helper.js b/plugins/c9.static/unpacked_helper.js new file mode 100644 index 00000000..15a3fe9a --- /dev/null +++ b/plugins/c9.static/unpacked_helper.js @@ -0,0 +1,42 @@ +"use strict"; + +plugin.consumes = [ + "db", "connect.static" +]; +plugin.provides = [ + "unpacked_helper" +]; + +module.exports = plugin; + +function plugin(options, imports, register) { + var connectStatic = imports["connect.static"]; + var assert = require("assert"); + var baseUrl = options.baseUrl; + var ideBaseUrl = options.ideBaseUrl; + assert(baseUrl, "baseUrl must be set"); + assert(ideBaseUrl, "ideBaseUrl must be set"); + + var balancers = [ + baseUrl + "/uph", + ]; + /* UNDONE: for now we put all static content on one domain + because of reports of CORS errors + if (!options.avoidSubdomains) + balancers.push( + ideBaseUrl + // We could include others but dogfooding URLs like + // vfs.newclient-lennartcl.c9.io don't have a cert, so + // let's not + // apiBaseUrl + "/uph", + // vfsBaseUrl + "/uph" + ); + */ + + connectStatic.getRequireJsConfig().baseUrlLoadBalancers = balancers; + assert(connectStatic.getRequireJsConfig().baseUrlLoadBalancers); + + register(null, { + "unpacked_helper": {} + }); +} \ No newline at end of file