forked from svrjs/svrjs
Lint out the codebase
This commit is contained in:
parent
b79e165bed
commit
04ab80cc95
13 changed files with 44 additions and 18 deletions
|
@ -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;
|
||||
};
|
||||
|
|
@ -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) {
|
||||
|
|
|
@ -112,4 +112,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -38,4 +38,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -463,4 +463,4 @@ module.exports.commands = {
|
|||
},
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -33,4 +33,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -80,4 +80,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -13,4 +13,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -154,4 +154,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -991,4 +991,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -135,4 +135,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -53,4 +53,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
|
@ -141,4 +141,4 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
next();
|
||||
};
|
||||
|
||||
module.exports.proxySafe = true;
|
||||
module.exports.proxySafe = true;
|
||||
|
|
Reference in a new issue