diff --git a/editor/js/i18n.js b/editor/js/i18n.js index 196488958..9e9695163 100644 --- a/editor/js/i18n.js +++ b/editor/js/i18n.js @@ -16,10 +16,13 @@ RED.i18n = (function() { + var apiRootUrl; + return { - init: function(done) { + init: function(options, done) { + apiRootUrl = options.apiRootUrl||""; i18n.init({ - resGetPath: 'locales/__ns__?lng=__lng__', + resGetPath: apiRootUrl+'locales/__ns__?lng=__lng__', dynamicLoad: false, load:'current', ns: { @@ -45,7 +48,7 @@ RED.i18n = (function() { "Accept":"application/json" }, cache: false, - url: 'nodes/'+namespace+'/messages?lng='+lang, + url: apiRootUrl+'nodes/'+namespace+'/messages?lng='+lang, success: function(data) { i18n.addResourceBundle(lang,namespace,data); toLoad--; @@ -68,7 +71,7 @@ RED.i18n = (function() { "Accept":"application/json" }, cache: false, - url: 'nodes/messages?lng='+lang, + url: apiRootUrl+'nodes/messages?lng='+lang, success: function(data) { var namespaces = Object.keys(data); namespaces.forEach(function(ns) { diff --git a/editor/js/main.js b/editor/js/main.js index b01136386..7aeea168e 100644 --- a/editor/js/main.js +++ b/editor/js/main.js @@ -18,5 +18,7 @@ $(function() { if ((window.location.hostname !== "localhost") && (window.location.hostname !== "127.0.0.1")) { document.title = document.title+" : "+window.location.hostname; } - RED.init(); + RED.init({ + apiRootUrl: "" + }); }); diff --git a/editor/js/red.js b/editor/js/red.js index 74ebb1187..ff629f378 100644 --- a/editor/js/red.js +++ b/editor/js/red.js @@ -463,12 +463,21 @@ var RED = (function() { loadNodeList(); } + var initialised = false; - function init() { + function init(options) { + if (initialised) { + throw new Error("RED already initialised"); + } + initialised = true; ace.require("ace/ext/language_tools"); - - RED.i18n.init(function() { - RED.settings.init(loadEditor); + options = options || {}; + options.apiRootUrl = options.apiRootUrl || ""; + if (options.apiRootUrl && !/\/$/.test(options.apiRootUrl)) { + options.apiRootUrl = options.apiRootUrl+"/"; + } + RED.i18n.init(options, function() { + RED.settings.init(options, loadEditor); }) } diff --git a/editor/js/settings.js b/editor/js/settings.js index 9594bec43..faf80c083 100644 --- a/editor/js/settings.js +++ b/editor/js/settings.js @@ -89,18 +89,22 @@ RED.settings = (function () { userSettings = data; } - var init = function (done) { + var init = function (options, done) { var accessTokenMatch = /[?&]access_token=(.*?)(?:$|&)/.exec(window.location.search); if (accessTokenMatch) { var accessToken = accessTokenMatch[1]; RED.settings.set("auth-tokens",{access_token: accessToken}); window.location.search = ""; } + RED.settings.apiRootUrl = options.apiRootUrl; $.ajaxSetup({ beforeSend: function(jqXHR,settings) { // Only attach auth header for requests to relative paths if (!/^\s*(https?:|\/|\.)/.test(settings.url)) { + if (options.apiRootUrl) { + settings.url = options.apiRootUrl+settings.url; + } var auth_tokens = RED.settings.get("auth-tokens"); if (auth_tokens) { jqXHR.setRequestHeader("Authorization","Bearer "+auth_tokens.access_token); diff --git a/editor/js/ui/utils.js b/editor/js/ui/utils.js index 9dd4d8ac2..23c3e3466 100644 --- a/editor/js/ui/utils.js +++ b/editor/js/ui/utils.js @@ -745,25 +745,25 @@ RED.utils = (function() { function getNodeIcon(def,node) { if (def.category === 'config') { - return "icons/node-red/cog.png" + return RED.settings.apiRootUrl+"icons/node-red/cog.png" } else if (node && node.type === 'tab') { - return "icons/node-red/subflow.png" + return RED.settings.apiRootUrl+"icons/node-red/subflow.png" } else if (node && node.type === 'unknown') { - return "icons/node-red/alert.png" + return RED.settings.apiRootUrl+"icons/node-red/alert.png" } else if (node && node.icon) { var iconPath = separateIconPath(node.icon); if (isIconExists(iconPath)) { - return "icons/" + node.icon; + return RED.settings.apiRootUrl+"icons/" + node.icon; } } var iconPath = getDefaultNodeIcon(def, node); if (def.category === 'subflows') { if (!isIconExists(iconPath)) { - return "icons/node-red/subflow.png"; + return RED.settings.apiRootUrl+"icons/node-red/subflow.png"; } } - return "icons/"+iconPath.module+"/"+iconPath.file; + return RED.settings.apiRootUrl+"icons/"+iconPath.module+"/"+iconPath.file; } function getNodeLabel(node,defaultLabel) {