From 322ceb7ea186eaed3bc3fc118b04d7be82ee118e Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 28 Mar 2019 17:17:40 +0100 Subject: [PATCH 1/2] process admin keys at startup, instead of on demand --- server.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 7cfc8471a..00496d902 100644 --- a/server.js +++ b/server.js @@ -169,16 +169,18 @@ if (config.privKeyAndCertFiles) { }; } +var admins = []; +try { + admins = (config.adminKeys || []).map(function (k) { + k = k.replace(/\/+$/, ''); + var s = k.split('/'); + return s[s.length-1].replace(/-/g, '/'); + }); +} catch (e) { console.error("Can't parse admin keys"); } + app.get('/api/config', function(req, res){ + // TODO precompute any data that isn't dynamic to save some CPU time var host = req.headers.host.replace(/\:[0-9]+/, ''); - var admins = []; - try { - admins = (config.adminKeys || []).map(function (k) { - k = k.replace(/\/+$/, ''); - var s = k.split('/'); - return s[s.length-1].replace(/-/g, '/'); - }); - } catch (e) { console.error("Can't parse admin keys"); } res.setHeader('Content-Type', 'text/javascript'); res.send('define(function(){\n' + [ 'var obj = ' + JSON.stringify({ From 8aeb6246d8b0173b246d7724c88b54aebb03f063 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 28 Mar 2019 17:18:04 +0100 Subject: [PATCH 2/2] expose admin email via /api/config --- server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server.js b/server.js index 00496d902..42a4c62fd 100644 --- a/server.js +++ b/server.js @@ -194,6 +194,7 @@ app.get('/api/config', function(req, res){ websocketURL:'ws' + ((useSecureWebsockets) ? 's' : '') + '://' + host + ':' + websocketPort + '/cryptpad_websocket', httpUnsafeOrigin: config.httpUnsafeOrigin, + adminEmail: config.adminEmail, adminKeys: admins, }, null, '\t'), 'obj.httpSafeOrigin = ' + (function () {