fix(middleware): skip logging for blocked connections to specific paths
Signed| @@ -55,6 +55,10 @@ export default function whitelistMiddleware(whitelistMode) { | ||
| 55 | 55 | safeReadFileSync('./public/error/forbidden-by-whitelist.html') ?? '', |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | + const noLogPaths = [ | |
| 59 | + '/favicon.ico', | |
| 60 | + ]; | |
| 61 | + | |
| 58 | 62 | return function (req, res, next) { |
| 59 | 63 | const clientIp = getIpFromRequest(req); |
| 60 | 64 | const forwardedIp = getForwardedIp(req); |
| @@ -68,11 +72,15 @@ export default function whitelistMiddleware(whitelistMode) { | ||
| 68 | 72 | const ipDetails = forwardedIp |
| 69 | 73 | ? `${clientIp} (forwarded from ${forwardedIp})` |
| 70 | 74 | : clientIp; |
| 75 | + | |
| 76 | + if (!noLogPaths.includes(req.path)) { | |
| 71 | 77 | console.warn( |
| 72 | 78 | color.red( |
| 73 | 79 | `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`, |
| 74 | 80 | ), |
| 75 | 81 | ); |
| 82 | + } | |
| 83 | + | |
| 76 | 84 | return res.status(403).send(forbiddenWebpage({ ipDetails })); |
| 77 | 85 | } |
| 78 | 86 | next(); |