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