diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/index.js b/packages/node_modules/@node-red/editor-api/lib/editor/index.js index 42be1f270..648daa09b 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/index.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/index.js @@ -51,7 +51,7 @@ module.exports = { var ui = require("./ui"); - ui.init(runtimeAPI); + ui.init(settings, runtimeAPI); const editorApp = apiUtil.createExpressApp(settings) diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/ui.js b/packages/node_modules/@node-red/editor-api/lib/editor/ui.js index 998816f5e..e7bf15069 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/ui.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/ui.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +const crypto = require('crypto') var express = require('express'); var fs = require("fs"); var path = require("path"); @@ -24,13 +25,16 @@ var apiUtils = require("../util"); var theme = require("./theme"); var runtimeAPI; +let settings; var editorClientDir = path.dirname(require.resolve("@node-red/editor-client")); var defaultNodeIcon = path.join(editorClientDir,"public","red","images","icons","arrow-in.svg"); var editorTemplatePath = path.join(editorClientDir,"templates","index.mst"); var editorTemplate; +let cacheBuster module.exports = { - init: function(_runtimeAPI) { + init: function(_settings, _runtimeAPI) { + settings = _settings; runtimeAPI = _runtimeAPI; editorTemplate = fs.readFileSync(editorTemplatePath,"utf8"); Mustache.parse(editorTemplate); @@ -91,6 +95,12 @@ module.exports = { }, editor: async function(req,res) { + if (!cacheBuster) { + // settings.instanceId is set asynchronously to the editor-api + // being initiaised. So we defer calculating the cacheBuster hash + // until the first load of the editor + cacheBuster = crypto.createHash('md5').update(`${settings.version || 'version'}-${settings.instanceId || 'instanceId'}`).digest("hex").substring(0,12) + } let sessionMessages; if (req.session && req.session.messages) { @@ -99,6 +109,7 @@ module.exports = { } res.send(Mustache.render(editorTemplate,{ sessionMessages, + cacheBuster, ...await theme.context() })); }, diff --git a/packages/node_modules/@node-red/editor-client/templates/index.mst b/packages/node_modules/@node-red/editor-client/templates/index.mst index 01bf06545..748a54bab 100644 --- a/packages/node_modules/@node-red/editor-client/templates/index.mst +++ b/packages/node_modules/@node-red/editor-client/templates/index.mst @@ -24,24 +24,24 @@