1
0
Fork 0
forked from svrjs/svrjs

Add middleware responsible for setting response headers (res.setHeader function).

This commit is contained in:
Dorian Niemiec 2024-08-24 17:32:27 +02:00
parent f552b34878
commit d688166022
3 changed files with 17 additions and 3 deletions

View file

@ -108,8 +108,10 @@ let middleware = [
require("./middleware/core.js"), require("./middleware/core.js"),
require("./middleware/urlSanitizer.js"), require("./middleware/urlSanitizer.js"),
require("./middleware/redirects.js"), require("./middleware/redirects.js"),
// TODO: blocklist
require("./middleware/webRootPostfixes.js"), require("./middleware/webRootPostfixes.js"),
require("./middleware/rewriteURL.js") require("./middleware/rewriteURL.js"),
require("./middleware/responseHeaders.js")
]; ];
function addMiddleware(mw) { function addMiddleware(mw) {

View file

@ -7,8 +7,6 @@ const serverHTTPErrorDescs = require("../res/httpErrorDescriptions.js");
const fixNodeMojibakeURL = require("../utils/urlMojibakeFixer.js"); const fixNodeMojibakeURL = require("../utils/urlMojibakeFixer.js");
const ipMatch = require("../utils/ipMatch.js"); const ipMatch = require("../utils/ipMatch.js");
const matchHostname = require("../utils/matchHostname.js"); const matchHostname = require("../utils/matchHostname.js");
const svrjsInfo = require("../../svrjs.json");
const version = svrjsInfo.version;
if (!process.err4xxcounter) process.err4xxcounter = 0; if (!process.err4xxcounter) process.err4xxcounter = 0;
if (!process.err5xxcounter) process.err5xxcounter = 0; if (!process.err5xxcounter) process.err5xxcounter = 0;

View file

@ -0,0 +1,14 @@
module.exports = (req, res, logFacilities, config, next) => {
if (!req.isProxy) {
var hkh = config.getCustomHeaders();
Object.keys(hkh).forEach(function (hkS) {
try {
res.setHeader(hkS, hkh[hkS]);
} catch (err) {
// Headers will not be set.
}
});
}
next();
};