Ensure Handlebars template is only compiled once

075368b5aec0cdb1d04c372f15bf1301b7ad2e57

Spappz <34202141+Spappz@users.noreply.github.com>

Signed
1 files changed, +7 -6Showing whitespace changes
src/middleware/whitelist.js+7 -6
@@ -15,6 +15,13 @@ let knownIPs = new Set();
1515const DEFAULT_WHITELIST_ERROR_MESSAGE =
1616 '<h1>Forbidden</h1><p>If you are the system administrator, add your IP address to the whitelist or disable whitelist mode by editing <code>config.yaml</code> in the root directory of your installation.</p><hr /><p><em>Connection from {{ipDetails}} has been blocked. This attempt has been logged.</em></p>';
1717
18+const errorMessage = Handlebars.compile(
19+ getConfigValue(
20+ 'whitelistErrorMessage',
21+ DEFAULT_WHITELIST_ERROR_MESSAGE,
22+ ),
23+);
24+
1825if (fs.existsSync(whitelistPath)) {
1926 try {
2027 let whitelistTxt = fs.readFileSync(whitelistPath, 'utf-8');
@@ -83,12 +90,6 @@ export default function whitelistMiddleware(whitelistMode, listen) {
8390 const ipDetails = forwardedIp
8491 ? `${clientIp} (forwarded from ${forwardedIp})`
8592 : clientIp;
86- const errorMessage = Handlebars.compile(
87- getConfigValue(
88- 'whitelistErrorMessage',
89- DEFAULT_WHITELIST_ERROR_MESSAGE,
90- ),
91- );
9293 console.log(
9394 color.red(
9495 `Blocked connection from ${clientIp}; User Agent: ${userAgent}\n\tTo allow this connection, add its IP address to the whitelist or disable whitelist mode by editing config.yaml in the root directory of your SillyTavern installation.\n`,