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 serverconsole = {};
|
||||||
let middleware = [];
|
let middleware = [];
|
||||||
|
|
||||||
|
@ -34,9 +36,26 @@ function proxyHandler(req, socket, head) {
|
||||||
var reqip = socket.remoteAddress;
|
var reqip = socket.remoteAddress;
|
||||||
var reqport = socket.remotePort;
|
var reqport = socket.remotePort;
|
||||||
process.reqcounter++;
|
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.locmessage(
|
||||||
logFacilities.reqmessage("Client " + ((!reqip || reqip == "") ? "[unknown client]" : (reqip + ((reqport && reqport !== 0) && reqport != "" ? ":" + reqport : ""))) + " wants to proxy " + req.url + " through this server");
|
"Somebody connected to " +
|
||||||
if (req.headers["user-agent"] != undefined) logFacilities.reqmessage("Client uses " + req.headers["user-agent"]);
|
(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;
|
let index = 0;
|
||||||
|
|
||||||
|
@ -55,10 +74,13 @@ function proxyHandler(req, socket, head) {
|
||||||
);
|
);
|
||||||
logFacilities.errmessage("Stack:");
|
logFacilities.errmessage("Stack:");
|
||||||
logFacilities.errmessage(err.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 {
|
} 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");
|
if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -72,4 +94,3 @@ module.exports = (serverconsoleO, middlewareO) => {
|
||||||
middleware = middlewareO;
|
middleware = middlewareO;
|
||||||
return proxyHandler;
|
return proxyHandler;
|
||||||
};
|
};
|
||||||
|
|
|
@ -710,7 +710,12 @@ function requestHandler(req, res) {
|
||||||
// Call the next middleware function
|
// Call the next middleware function
|
||||||
const next = () => {
|
const next = () => {
|
||||||
let currentMiddleware = middleware[index++];
|
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++];
|
currentMiddleware = middleware[index++];
|
||||||
}
|
}
|
||||||
if (currentMiddleware) {
|
if (currentMiddleware) {
|
||||||
|
|
Reference in a new issue