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

WIP - url rewriting to support debug

This commit is contained in:
Nick O'Leary 2018-05-14 14:32:58 +01:00
parent f82a779817
commit e41d5c249f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 60 additions and 29 deletions

View File

@ -15,7 +15,8 @@
**/ **/
var RED = (function() { var RED = (function() {
function appendNodeConfig(nodeConfig) { function appendNodeConfig(nodeConfig,done) {
done = done || function(){};
var m = /<!-- --- \[red-module:(\S+)\] --- -->/.exec(nodeConfig.trim()); var m = /<!-- --- \[red-module:(\S+)\] --- -->/.exec(nodeConfig.trim());
var moduleId; var moduleId;
if (m) { if (m) {
@ -24,13 +25,31 @@ var RED = (function() {
moduleId = "unknown"; moduleId = "unknown";
} }
try { try {
$("body").append(nodeConfig); var hasDeferred = false;
var nodeConfigEls = $("<div>"+nodeConfig+"</div>");
nodeConfigEls.find("script").each(function(i,el) {
var srcUrl = $(el).attr('src');
if (srcUrl && !/^\s*(https?:|\/|\.)/.test(srcUrl)) {
$(el).remove();
var newScript = document.createElement("script");
newScript.onload = function() { $("body").append(nodeConfigEls); done() }
$('body').append(newScript);
newScript.src = RED.settings.apiRootUrl+srcUrl;
hasDeferred = true;
}
})
if (!hasDeferred) {
$("body").append(nodeConfigEls);
done();
}
} catch(err) { } catch(err) {
RED.notify(RED._("notification.errors.failedToAppendNode",{module:moduleId, error:err.toString()}),{ RED.notify(RED._("notification.errors.failedToAppendNode",{module:moduleId, error:err.toString()}),{
type: "error", type: "error",
timeout: 10000 timeout: 10000
}); });
console.log("["+moduleId+"] "+err.toString()); console.log("["+moduleId+"] "+err.toString());
done();
} }
} }
@ -75,10 +94,8 @@ var RED = (function() {
url: 'nodes', url: 'nodes',
success: function(data) { success: function(data) {
var configs = data.trim().split(/(?=<!-- --- \[red-module:\S+\] --- -->)/); var configs = data.trim().split(/(?=<!-- --- \[red-module:\S+\] --- -->)/);
configs.forEach(function(data) { var stepConfig = function() {
appendNodeConfig(data); if (configs.length === 0) {
});
$("body").i18n(); $("body").i18n();
$("#palette > .palette-spinner").hide(); $("#palette > .palette-spinner").hide();
$(".palette-scroll").removeClass("hide"); $(".palette-scroll").removeClass("hide");
@ -105,6 +122,12 @@ var RED = (function() {
completeLoad(); completeLoad();
} }
}); });
} else {
var config = configs.shift();
appendNodeConfig(config,stepConfig);
}
}
stepConfig();
} }
}); });
} }

View File

@ -1,5 +1,5 @@
$(function() { $(function() {
RED.i18n.init(function() { RED.i18n.init({},function() {
var options = { var options = {
messageMouseEnter: function(sourceId) { messageMouseEnter: function(sourceId) {
window.opener.postMessage({event:"mouseEnter",id:sourceId},'*'); window.opener.postMessage({event:"mouseEnter",id:sourceId},'*');

View File

@ -32,6 +32,14 @@ function init(_server,settings,storage,runtimeAPI) {
server = _server; server = _server;
if (settings.httpAdminRoot !== false) { if (settings.httpAdminRoot !== false) {
adminApp = express(); adminApp = express();
var cors = require('cors');
var corsHandler = cors({
origin: "*",
methods: "GET,PUT,POST,DELETE"
});
adminApp.use(corsHandler);
auth.init(settings,storage); auth.init(settings,storage);
var maxApiRequestSize = settings.apiMaxLength || '5mb'; var maxApiRequestSize = settings.apiMaxLength || '5mb';