diff --git a/lib/env.js b/lib/env.js index 64280193b..1923dcc9e 100644 --- a/lib/env.js +++ b/lib/env.js @@ -27,6 +27,25 @@ var deriveSandboxOrigin = function (unsafe, port) { return url.origin; }; +var isRecentVersion = function () { + var V = process.version; + if (typeof(V) !== 'string') { return false; } + var parts = V.replace(/^v/, '').split('.').map(Number); + if (parts.length < 3) { return false; } + if (!parts.every(n => typeof(n) === 'number' && !isNaN(n))) { + return false; + } + if (parts[0] < 16) { return false; } + if (parts[0] > 16) { return true; } + + // v16 + if (parts[1] < 14) { return false; } + if (parts[1] > 14) { return true; } + if (parts[2] >= 2) { return true; } + + return false; +}; + module.exports.create = function (config) { var httpUnsafeOrigin = canonicalizeOrigin(config.httpUnsafeOrigin); @@ -53,6 +72,8 @@ module.exports.create = function (config) { NO_SANDBOX: NO_SANDBOX, httpSafePort: httpSafePort, + shouldUpdateNode: !isRecentVersion(), + version: Package.version, installMethod: config.installMethod || undefined, diff --git a/server.js b/server.js index 73e4d2b00..80df1b526 100644 --- a/server.js +++ b/server.js @@ -236,6 +236,7 @@ var serveConfig = makeRouteCache(function (host) { httpSafeOrigin: Env.httpSafeOrigin, disableEmbedding: Env.disableEmbedding, fileHost: Env.fileHost, + shouldUpdateNode: Env.shouldUpdateNode || undefined, }, null, '\t'), '});' ].join(';\n') @@ -325,6 +326,13 @@ nThen(function (w) { Env.Log = _log; config.log = _log; + if (Env.shouldUpdateNode) { + Env.Log.warn("NODEJS_OLD_VERSION", { + message: `The CryptPad development team recommends using at least NodeJS v16.14.2`, + currentVersion: process.version, + }); + } + if (Env.OFFLINE_MODE) { return; } if (Env.websocketPath) { return; } diff --git a/www/checkup/main.js b/www/checkup/main.js index 76f6b88d7..204c9082e 100644 --- a/www/checkup/main.js +++ b/www/checkup/main.js @@ -1310,6 +1310,21 @@ define([ }); }); + assert(function (cb, msg) { + msg.appendChild(h('span', [ + "The CryptPad development team recommends running at least NodeJS ", + code("v16.14.2"), + ". Which can be installed and updated via ", + h('a', { + href: 'https://github.com/nvm-sh/nvm', + rel: 'noopener noreferer', + target: '_blank', + }, 'NVM'), + '.', + ])); + cb(!ApiConfig.shouldUpdateNode); + }); + var serverToken; Tools.common_xhr('/', function (xhr) { serverToken = xhr.getResponseHeader('server');