1
0
Fork 0
forked from svrjs/svrjs

Lint out the codebase

This commit is contained in:
Dorian Niemiec 2024-08-25 12:56:36 +02:00
parent b79e165bed
commit 04ab80cc95
13 changed files with 44 additions and 18 deletions

View file

@ -1,3 +1,5 @@
const generateServerString = require("../utils/generateServerString");
let serverconsole = {};
let middleware = [];
@ -34,9 +36,26 @@ function proxyHandler(req, socket, head) {
var reqip = socket.remoteAddress;
var reqport = socket.remotePort;
process.reqcounter++;
logFacilities.locmessage("Somebody connected to " + (config.secure ? ((typeof config.sport == "number" ? "port " : "socket ") + sport) : ((typeof config.port == "number" ? "port " : "socket ") + config.port)) + "...");
logFacilities.reqmessage("Client " + ((!reqip || reqip == "") ? "[unknown client]" : (reqip + ((reqport && reqport !== 0) && reqport != "" ? ":" + reqport : ""))) + " wants to proxy " + req.url + " through this server");
if (req.headers["user-agent"] != undefined) logFacilities.reqmessage("Client uses " + req.headers["user-agent"]);
logFacilities.locmessage(
"Somebody connected to " +
(config.secure
? (typeof config.sport == "number" ? "port " : "socket ") + config.sport
: (typeof config.port == "number" ? "port " : "socket ") +
config.port) +
"...",
);
logFacilities.reqmessage(
"Client " +
(!reqip || reqip == ""
? "[unknown client]"
: reqip +
(reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")) +
" wants to proxy " +
req.url +
" through this server",
);
if (req.headers["user-agent"] != undefined)
logFacilities.reqmessage("Client uses " + req.headers["user-agent"]);
let index = 0;
@ -55,10 +74,13 @@ function proxyHandler(req, socket, head) {
);
logFacilities.errmessage("Stack:");
logFacilities.errmessage(err.stack);
if (!socket.destroyed) socket.end("HTTP/1.1 500 Internal Server Error\n\n");
if (!socket.destroyed)
socket.end("HTTP/1.1 500 Internal Server Error\n\n");
}
} else {
logFacilities.errmessage("SVR.JS doesn't support proxy without proxy mod.");
logFacilities.errmessage(
"SVR.JS doesn't support proxy without proxy mod.",
);
if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n");
}
};
@ -72,4 +94,3 @@ module.exports = (serverconsoleO, middlewareO) => {
middleware = middlewareO;
return proxyHandler;
};

View file

@ -710,7 +710,12 @@ function requestHandler(req, res) {
// Call the next middleware function
const next = () => {
let currentMiddleware = middleware[index++];
while (req.isProxy && currentMiddleware && currentMiddleware.proxySafe !== false && !(currentMiddleware.proxySafe || currentMiddleware.proxy)) {
while (
req.isProxy &&
currentMiddleware &&
currentMiddleware.proxySafe !== false &&
!(currentMiddleware.proxySafe || currentMiddleware.proxy)
) {
currentMiddleware = middleware[index++];
}
if (currentMiddleware) {

View file

@ -112,4 +112,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -38,4 +38,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -463,4 +463,4 @@ module.exports.commands = {
},
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -33,4 +33,4 @@ module.exports = (req, res, logFacilities, config, next) => {
}
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -80,4 +80,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -13,4 +13,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -154,4 +154,4 @@ module.exports = (req, res, logFacilities, config, next) => {
});
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -991,4 +991,4 @@ module.exports = (req, res, logFacilities, config, next) => {
});
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -135,4 +135,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -53,4 +53,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;

View file

@ -141,4 +141,4 @@ module.exports = (req, res, logFacilities, config, next) => {
next();
};
module.exports.proxySafe = true;
module.exports.proxySafe = true;