1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow the editor to use a custom admin api url root

This commit is contained in:
Nick O'Leary 2018-05-11 13:26:26 +01:00
parent 0c7f4e2168
commit 28fe1e4c8f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 34 additions and 16 deletions

View File

@ -16,10 +16,13 @@
RED.i18n = (function() { RED.i18n = (function() {
var apiRootUrl;
return { return {
init: function(done) { init: function(options, done) {
apiRootUrl = options.apiRootUrl||"";
i18n.init({ i18n.init({
resGetPath: 'locales/__ns__?lng=__lng__', resGetPath: apiRootUrl+'locales/__ns__?lng=__lng__',
dynamicLoad: false, dynamicLoad: false,
load:'current', load:'current',
ns: { ns: {
@ -45,7 +48,7 @@ RED.i18n = (function() {
"Accept":"application/json" "Accept":"application/json"
}, },
cache: false, cache: false,
url: 'nodes/'+namespace+'/messages?lng='+lang, url: apiRootUrl+'nodes/'+namespace+'/messages?lng='+lang,
success: function(data) { success: function(data) {
i18n.addResourceBundle(lang,namespace,data); i18n.addResourceBundle(lang,namespace,data);
toLoad--; toLoad--;
@ -68,7 +71,7 @@ RED.i18n = (function() {
"Accept":"application/json" "Accept":"application/json"
}, },
cache: false, cache: false,
url: 'nodes/messages?lng='+lang, url: apiRootUrl+'nodes/messages?lng='+lang,
success: function(data) { success: function(data) {
var namespaces = Object.keys(data); var namespaces = Object.keys(data);
namespaces.forEach(function(ns) { namespaces.forEach(function(ns) {

View File

@ -18,5 +18,7 @@ $(function() {
if ((window.location.hostname !== "localhost") && (window.location.hostname !== "127.0.0.1")) { if ((window.location.hostname !== "localhost") && (window.location.hostname !== "127.0.0.1")) {
document.title = document.title+" : "+window.location.hostname; document.title = document.title+" : "+window.location.hostname;
} }
RED.init(); RED.init({
apiRootUrl: ""
});
}); });

View File

@ -463,12 +463,21 @@ var RED = (function() {
loadNodeList(); 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"); ace.require("ace/ext/language_tools");
options = options || {};
RED.i18n.init(function() { options.apiRootUrl = options.apiRootUrl || "";
RED.settings.init(loadEditor); if (options.apiRootUrl && !/\/$/.test(options.apiRootUrl)) {
options.apiRootUrl = options.apiRootUrl+"/";
}
RED.i18n.init(options, function() {
RED.settings.init(options, loadEditor);
}) })
} }

View File

@ -89,18 +89,22 @@ RED.settings = (function () {
userSettings = data; userSettings = data;
} }
var init = function (done) { var init = function (options, done) {
var accessTokenMatch = /[?&]access_token=(.*?)(?:$|&)/.exec(window.location.search); var accessTokenMatch = /[?&]access_token=(.*?)(?:$|&)/.exec(window.location.search);
if (accessTokenMatch) { if (accessTokenMatch) {
var accessToken = accessTokenMatch[1]; var accessToken = accessTokenMatch[1];
RED.settings.set("auth-tokens",{access_token: accessToken}); RED.settings.set("auth-tokens",{access_token: accessToken});
window.location.search = ""; window.location.search = "";
} }
RED.settings.apiRootUrl = options.apiRootUrl;
$.ajaxSetup({ $.ajaxSetup({
beforeSend: function(jqXHR,settings) { beforeSend: function(jqXHR,settings) {
// Only attach auth header for requests to relative paths // Only attach auth header for requests to relative paths
if (!/^\s*(https?:|\/|\.)/.test(settings.url)) { if (!/^\s*(https?:|\/|\.)/.test(settings.url)) {
if (options.apiRootUrl) {
settings.url = options.apiRootUrl+settings.url;
}
var auth_tokens = RED.settings.get("auth-tokens"); var auth_tokens = RED.settings.get("auth-tokens");
if (auth_tokens) { if (auth_tokens) {
jqXHR.setRequestHeader("Authorization","Bearer "+auth_tokens.access_token); jqXHR.setRequestHeader("Authorization","Bearer "+auth_tokens.access_token);

View File

@ -745,25 +745,25 @@ RED.utils = (function() {
function getNodeIcon(def,node) { function getNodeIcon(def,node) {
if (def.category === 'config') { 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') { } 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') { } 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) { } else if (node && node.icon) {
var iconPath = separateIconPath(node.icon); var iconPath = separateIconPath(node.icon);
if (isIconExists(iconPath)) { if (isIconExists(iconPath)) {
return "icons/" + node.icon; return RED.settings.apiRootUrl+"icons/" + node.icon;
} }
} }
var iconPath = getDefaultNodeIcon(def, node); var iconPath = getDefaultNodeIcon(def, node);
if (def.category === 'subflows') { if (def.category === 'subflows') {
if (!isIconExists(iconPath)) { 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) { function getNodeLabel(node,defaultLabel) {