From 00d01e7cf5cd8043abbff7dff6d469cb9047f9cf Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 23 Aug 2024 21:46:08 +0200 Subject: [PATCH] Replace "var" with "let" in core middleware, and add req.authUser set to null. --- src/middleware/core.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/middleware/core.js b/src/middleware/core.js index 75a9a95..fe645d2 100644 --- a/src/middleware/core.js +++ b/src/middleware/core.js @@ -137,7 +137,7 @@ module.exports = (req, res, logFacilities, config, next) => { } /*if (req.headers["x-svr-js-from-main-thread"] == "true" && req.socket && (!req.socket.remoteAddress || req.socket.remoteAddress == "::1" || req.socket.remoteAddress == "::ffff:127.0.0.1" || req.socket.remoteAddress == "127.0.0.1" || req.socket.remoteAddress == "localhost" || req.socket.remoteAddress == host || req.socket.remoteAddress == "::ffff:" + host)) { - var headers = config.getCustomHeaders(); + let headers = config.getCustomHeaders(); res.writeHead(204, http.STATUS_CODES[204], headers); res.end(); return; @@ -145,8 +145,8 @@ module.exports = (req, res, logFacilities, config, next) => { req.url = fixNodeMojibakeURL(req.url); - var headWritten = false; - var lastStatusCode = null; + let headWritten = false; + let lastStatusCode = null; res.writeHeadNative = res.writeHead; res.writeHead = function (code, codeDescription, headers) { if ( @@ -186,7 +186,7 @@ module.exports = (req, res, logFacilities, config, next) => { res.writeHeadNative(code, codeDescription, headers); }; - var finished = false; + let finished = false; res.on("finish", function () { if (!finished) { finished = true; @@ -260,7 +260,7 @@ module.exports = (req, res, logFacilities, config, next) => { process.reqcounter++; // Process the Host header - var oldHostHeader = req.headers.host; + let oldHostHeader = req.headers.host; if (typeof req.headers.host == "string") { req.headers.host = req.headers.host.toLowerCase(); if (!req.headers.host.match(/^\.+$/)) @@ -660,6 +660,9 @@ module.exports = (req, res, logFacilities, config, next) => { return; }; + // Authenticated user variable + req.authUser = null; + if (req.url == "*") { // Handle "*" URL if (req.method == "OPTIONS") {