mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
refactor(Middleware): only mount accessLogger when listen is enabled
This commit is contained in:
@ -344,7 +344,9 @@ app.use(CORS);
|
||||
if (listen && basicAuthMode) app.use(basicAuthMiddleware);
|
||||
|
||||
app.use(whitelistMiddleware(enableWhitelist));
|
||||
app.use(accessLoggerMiddleware(listen));
|
||||
if (listen) {
|
||||
app.use(accessLoggerMiddleware());
|
||||
}
|
||||
|
||||
if (enableCorsProxy) {
|
||||
app.use(bodyParser.json({
|
||||
|
@ -28,15 +28,14 @@ export function migrateAccessLog() {
|
||||
|
||||
/**
|
||||
* Creates middleware for logging access and new connections
|
||||
* @param {boolean} listen If listen mode is enabled via config or command line
|
||||
* @returns {import('express').RequestHandler}
|
||||
*/
|
||||
export default function accessLoggerMiddleware(listen) {
|
||||
export default function accessLoggerMiddleware() {
|
||||
return function (req, res, next) {
|
||||
const clientIp = getRealIpFromHeader(req);
|
||||
const userAgent = req.headers['user-agent'];
|
||||
|
||||
if (listen && !knownIPs.has(clientIp)) {
|
||||
if (!knownIPs.has(clientIp)) {
|
||||
// Log new connection
|
||||
console.info(color.yellow(`New connection from ${clientIp}; User Agent: ${userAgent}\n`));
|
||||
knownIPs.add(clientIp);
|
||||
|
Reference in New Issue
Block a user