perf: move out nconf.get and isClientScript regex

This commit is contained in:
Barış Soner Uşaklı
2026-03-12 22:13:38 -04:00
parent 59dd22ca2e
commit 4d55ee0a55

View File

@@ -9,12 +9,17 @@ const plugins = require('../plugins');
const activitypub = require('../activitypub');
const middleware = require('../middleware');
const helpers = require('../middleware/helpers');
const { secureRandom } = require('../utils');
const relativePath = nconf.get('relative_path');
const isClientScript = new RegExp(`^${relativePath}\\/assets\\/src\\/.+\\.js(\\?v=\\w+)?$`);
const error404Icons = [
'fa-hippo', 'fa-cat', 'fa-otter',
'fa-dog', 'fa-cow', 'fa-fish',
'fa-dragon', 'fa-horse', 'fa-dove',
];
exports.handle404 = helpers.try(async (req, res) => {
const relativePath = nconf.get('relative_path');
const isClientScript = new RegExp(`^${relativePath}\\/assets\\/src\\/.+\\.js(\\?v=\\w+)?$`);
if (plugins.hooks.hasListeners('action:meta.override404')) {
return plugins.hooks.fire('action:meta.override404', {
req: req,
@@ -62,16 +67,12 @@ exports.send404 = helpers.try(async (req, res) => {
bodyClass: helpers.buildBodyClass(req, res),
});
}
const icons = [
'fa-hippo', 'fa-cat', 'fa-otter',
'fa-dog', 'fa-cow', 'fa-fish',
'fa-dragon', 'fa-horse', 'fa-dove',
];
await middleware.buildHeaderAsync(req, res);
res.render('404', {
path: validator.escape(path),
title: '[[global:404.title]]',
bodyClass: helpers.buildBodyClass(req, res),
icon: icons[secureRandom(0, icons.length - 1)],
icon: error404Icons[Math.floor(Math.random() * error404Icons.length)],
});
});