performance improvements (#8795)

* perf: nconf/winston/render

cache nconf.get calls
modify middleware.pageView to call next earlier
don't call winston.verbose on every hook see https://github.com/winstonjs/winston/issues/1669
translate header/footer separately and cache results for guests

* fix: copy paste fail

* refactor: style and fire hook only log in dev mode

* fix: cache key, header changes based on template

* perf: change replace

* fix: add missing await

* perf: category

* perf: lodash clone

* perf: remove escapeRegexChars
This commit is contained in:
Barış Soner Uşaklı
2020-10-26 10:43:18 -04:00
committed by GitHub
parent 822c13f199
commit a05905f196
34 changed files with 230 additions and 193 deletions

View File

@@ -3,7 +3,6 @@
const os = require('os');
const nconf = require('nconf');
const winston = require('winston');
const url = require('url');
const util = require('util');
const cookieParser = require('cookie-parser')(nconf.get('secret'));
@@ -47,14 +46,7 @@ Sockets.init = function (server) {
* Can be overridden via config (socket.io:origins)
*/
if (process.env.NODE_ENV !== 'development') {
const parsedUrl = url.parse(nconf.get('url'));
// cookies don't provide isolation by port: http://stackoverflow.com/a/16328399/122353
const domain = nconf.get('cookieDomain') || parsedUrl.hostname;
const origins = nconf.get('socket.io:origins') || `${parsedUrl.protocol}//${domain}:*`;
nconf.set('socket.io:origins', origins);
const origins = nconf.get('socket.io:origins');
io.origins(origins);
winston.info('[socket.io] Restricting access to origin: ' + origins);
}