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();
15const DEFAULT_WHITELIST_ERROR_MESSAGE =15const DEFAULT_WHITELIST_ERROR_MESSAGE =
16 '<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>';16 '<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
18const errorMessage = Handlebars.compile(
19 getConfigValue(
20 'whitelistErrorMessage',
21 DEFAULT_WHITELIST_ERROR_MESSAGE,
22 ),
23);
24
18if (fs.existsSync(whitelistPath)) {25if (fs.existsSync(whitelistPath)) {
19 try {26 try {
20 let whitelistTxt = fs.readFileSync(whitelistPath, 'utf-8');27 let whitelistTxt = fs.readFileSync(whitelistPath, 'utf-8');
@@ -83,12 +90,6 @@ export default function whitelistMiddleware(whitelistMode, listen) {
83 const ipDetails = forwardedIp90 const ipDetails = forwardedIp
84 ? `${clientIp} (forwarded from ${forwardedIp})`91 ? `${clientIp} (forwarded from ${forwardedIp})`
85 : clientIp;92 : clientIp;
86 const errorMessage = Handlebars.compile(
87 getConfigValue(
88 'whitelistErrorMessage',
89 DEFAULT_WHITELIST_ERROR_MESSAGE,
90 ),
91 );
92 console.log(93 console.log(
93 color.red(94 color.red(
94 `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`,95 `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`,