@node-red/editor-api 3.1.3 → 3.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@ module.exports = {
51
51
 
52
52
  var ui = require("./ui");
53
53
 
54
- ui.init(runtimeAPI);
54
+ ui.init(settings, runtimeAPI);
55
55
 
56
56
  const editorApp = apiUtil.createExpressApp(settings)
57
57
 
package/lib/editor/ui.js CHANGED
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  **/
16
+ const crypto = require('crypto')
16
17
  var express = require('express');
17
18
  var fs = require("fs");
18
19
  var path = require("path");
@@ -24,13 +25,16 @@ var apiUtils = require("../util");
24
25
  var theme = require("./theme");
25
26
 
26
27
  var runtimeAPI;
28
+ let settings;
27
29
  var editorClientDir = path.dirname(require.resolve("@node-red/editor-client"));
28
30
  var defaultNodeIcon = path.join(editorClientDir,"public","red","images","icons","arrow-in.svg");
29
31
  var editorTemplatePath = path.join(editorClientDir,"templates","index.mst");
30
32
  var editorTemplate;
33
+ let cacheBuster
31
34
 
32
35
  module.exports = {
33
- init: function(_runtimeAPI) {
36
+ init: function(_settings, _runtimeAPI) {
37
+ settings = _settings;
34
38
  runtimeAPI = _runtimeAPI;
35
39
  editorTemplate = fs.readFileSync(editorTemplatePath,"utf8");
36
40
  Mustache.parse(editorTemplate);
@@ -91,6 +95,12 @@ module.exports = {
91
95
  },
92
96
 
93
97
  editor: async function(req,res) {
98
+ if (!cacheBuster) {
99
+ // settings.instanceId is set asynchronously to the editor-api
100
+ // being initiaised. So we defer calculating the cacheBuster hash
101
+ // until the first load of the editor
102
+ cacheBuster = crypto.createHash('md5').update(`${settings.version || 'version'}-${settings.instanceId || 'instanceId'}`).digest("hex").substring(0,12)
103
+ }
94
104
 
95
105
  let sessionMessages;
96
106
  if (req.session && req.session.messages) {
@@ -99,6 +109,7 @@ module.exports = {
99
109
  }
100
110
  res.send(Mustache.render(editorTemplate,{
101
111
  sessionMessages,
112
+ cacheBuster,
102
113
  ...await theme.context()
103
114
  }));
104
115
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/editor-api",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,8 +16,8 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/util": "3.1.3",
20
- "@node-red/editor-client": "3.1.3",
19
+ "@node-red/util": "3.1.5",
20
+ "@node-red/editor-client": "3.1.5",
21
21
  "bcryptjs": "2.4.3",
22
22
  "body-parser": "1.20.2",
23
23
  "clone": "2.1.2",