forked from svrjs/svrjs
Lint out the codebase.
This commit is contained in:
parent
2075d41ab3
commit
e94391f197
4 changed files with 34 additions and 29 deletions
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
Reference in a new issue