1
0
Fork 0
forked from svrjs/svrjs

Replace "var" with "let" in core middleware, and add req.authUser set to null.

This commit is contained in:
Dorian Niemiec 2024-08-23 21:46:08 +02:00
parent 0e8b8392a4
commit 00d01e7cf5

View file

@ -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)) { /*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.writeHead(204, http.STATUS_CODES[204], headers);
res.end(); res.end();
return; return;
@ -145,8 +145,8 @@ module.exports = (req, res, logFacilities, config, next) => {
req.url = fixNodeMojibakeURL(req.url); req.url = fixNodeMojibakeURL(req.url);
var headWritten = false; let headWritten = false;
var lastStatusCode = null; let lastStatusCode = null;
res.writeHeadNative = res.writeHead; res.writeHeadNative = res.writeHead;
res.writeHead = function (code, codeDescription, headers) { res.writeHead = function (code, codeDescription, headers) {
if ( if (
@ -186,7 +186,7 @@ module.exports = (req, res, logFacilities, config, next) => {
res.writeHeadNative(code, codeDescription, headers); res.writeHeadNative(code, codeDescription, headers);
}; };
var finished = false; let finished = false;
res.on("finish", function () { res.on("finish", function () {
if (!finished) { if (!finished) {
finished = true; finished = true;
@ -260,7 +260,7 @@ module.exports = (req, res, logFacilities, config, next) => {
process.reqcounter++; process.reqcounter++;
// Process the Host header // Process the Host header
var oldHostHeader = req.headers.host; let oldHostHeader = req.headers.host;
if (typeof req.headers.host == "string") { if (typeof req.headers.host == "string") {
req.headers.host = req.headers.host.toLowerCase(); req.headers.host = req.headers.host.toLowerCase();
if (!req.headers.host.match(/^\.+$/)) if (!req.headers.host.match(/^\.+$/))
@ -660,6 +660,9 @@ module.exports = (req, res, logFacilities, config, next) => {
return; return;
}; };
// Authenticated user variable
req.authUser = null;
if (req.url == "*") { if (req.url == "*") {
// Handle "*" URL // Handle "*" URL
if (req.method == "OPTIONS") { if (req.method == "OPTIONS") {