forked from svrjs/svrjs
Add middleware responsible for setting response headers (res.setHeader function).
This commit is contained in:
parent
f552b34878
commit
d688166022
3 changed files with 17 additions and 3 deletions
|
@ -108,8 +108,10 @@ let middleware = [
|
|||
require("./middleware/core.js"),
|
||||
require("./middleware/urlSanitizer.js"),
|
||||
require("./middleware/redirects.js"),
|
||||
// TODO: blocklist
|
||||
require("./middleware/webRootPostfixes.js"),
|
||||
require("./middleware/rewriteURL.js")
|
||||
require("./middleware/rewriteURL.js"),
|
||||
require("./middleware/responseHeaders.js")
|
||||
];
|
||||
|
||||
function addMiddleware(mw) {
|
||||
|
|
|
@ -7,8 +7,6 @@ const serverHTTPErrorDescs = require("../res/httpErrorDescriptions.js");
|
|||
const fixNodeMojibakeURL = require("../utils/urlMojibakeFixer.js");
|
||||
const ipMatch = require("../utils/ipMatch.js");
|
||||
const matchHostname = require("../utils/matchHostname.js");
|
||||
const svrjsInfo = require("../../svrjs.json");
|
||||
const version = svrjsInfo.version;
|
||||
|
||||
if (!process.err4xxcounter) process.err4xxcounter = 0;
|
||||
if (!process.err5xxcounter) process.err5xxcounter = 0;
|
||||
|
|
14
src/middleware/responseHeaders.js
Normal file
14
src/middleware/responseHeaders.js
Normal 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();
|
||||
};
|
Reference in a new issue