1
0
Fork 0
forked from svrjs/svrjs

Lint out the codebase.

This commit is contained in:
Dorian Niemiec 2024-08-24 20:45:17 +02:00
parent 2075d41ab3
commit e94391f197
4 changed files with 34 additions and 29 deletions

View file

@ -2,30 +2,33 @@ const fs = require("fs");
module.exports = (req, res, logFacilities, config, next) => {
// Trailing slash redirection
if (
!req.isProxy &&
!config.disableTrailingSlashRedirects &&
req.parsedURL.pathname[req.parsedURL.pathname.length - 1] != "/" &&
req.originalParsedURL.pathname[
req.originalParsedURL.pathname.length - 1
] != "/"
) {
fs.stat(
"." + decodeURIComponent(req.parsedURL.pathname),
function (err, stats) {
if (err || !stats.isDirectory()) {
try {
next();
} catch (err) {
res.error(500, err);
}
} else {
res.redirect(req.originalParsedURL.pathname + "/" + req.parsedURL.search + req.parsedURL.hash);
if (
!req.isProxy &&
!config.disableTrailingSlashRedirects &&
req.parsedURL.pathname[req.parsedURL.pathname.length - 1] != "/" &&
req.originalParsedURL.pathname[req.originalParsedURL.pathname.length - 1] !=
"/"
) {
fs.stat(
"." + decodeURIComponent(req.parsedURL.pathname),
function (err, stats) {
if (err || !stats.isDirectory()) {
try {
next();
} catch (err) {
res.error(500, err);
}
},
);
} else {
next();
}
} else {
res.redirect(
req.originalParsedURL.pathname +
"/" +
req.parsedURL.search +
req.parsedURL.hash,
);
}
},
);
} else {
next();
}
};

View file

@ -125,7 +125,8 @@ module.exports = (req, res, logFacilities, config, next) => {
logFacilities.errmessage("Content blocked.");
return;
} else if (sHref != req.parsedURL.pathname) {
var rewrittenAgainURL = sHref + req.parsedURL.search + req.parsedURL.hash;
var rewrittenAgainURL =
sHref + req.parsedURL.search + req.parsedURL.hash;
logFacilities.resmessage(
"URL sanitized: " + req.url + " => " + rewrittenAgainURL,
);

View file

@ -11,7 +11,8 @@ module.exports = (req, res, logFacilities, config, next) => {
// Check if URL is "dirty"
if (req.parsedURL.pathname != sanitizedHref && !req.isProxy) {
let sanitizedURL = sanitizedHref + req.parsedURL.search + req.parsedURL.hash;
let sanitizedURL =
sanitizedHref + req.parsedURL.search + req.parsedURL.hash;
logFacilities.resmessage(
"URL sanitized: " + req.url + " => " + sanitizedURL,
);

View file

@ -1,4 +1,3 @@
const url = require("url");
const createRegex = require("../utils/createRegex.js");
const ipMatch = require("../utils/ipMatch.js");
const sanitizeURL = require("../utils/urlSanitizer.js");
@ -113,7 +112,8 @@ module.exports = (req, res, logFacilities, config, next) => {
logFacilities.errmessage("Content blocked.");
return;
} else if (sHref != req.parsedURL.pathname) {
let rewrittenAgainURL = sHref + req.parsedURL.search + req.parsedURL.hash;
let rewrittenAgainURL =
sHref + req.parsedURL.search + req.parsedURL.hash;
logFacilities.resmessage(
"URL sanitized: " + req.url + " => " + rewrittenAgainURL,
);