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:
parent
0c7f4e2168
commit
28fe1e4c8f
@ -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) {
|
||||
|
@ -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: ""
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user