diff --git a/src/middleware/core.js b/src/middleware/core.js index 3dc8718..fcfae35 100644 --- a/src/middleware/core.js +++ b/src/middleware/core.js @@ -464,20 +464,7 @@ module.exports = (req, res, logFacilities, config, next) => { /{server}/g, "" + ( - (config.exposeServerVersion - ? "SVR.JS/" + - version + - " (" + - getOS() + - "; " + - (process.isBun - ? "Bun/v" + - process.versions.bun + - "; like Node.JS/" + - process.version - : "Node.JS/" + process.version) + - ")" - : "SVR.JS") + + config.generateServerString() + (!config.exposeModsInErrorPages || extName == undefined ? "" : " " + extName) diff --git a/src/utils/generateServerString.js b/src/utils/generateServerString.js index 7e0e7bb..802469c 100644 --- a/src/utils/generateServerString.js +++ b/src/utils/generateServerString.js @@ -1,20 +1,20 @@ const svrjsInfo = require("../../svrjs.json"); -const {version, name} = svrjsInfo; +const { version, name } = svrjsInfo; const getOS = require("./getOS.js"); function generateServerString(exposeServerVersion) { return exposeServerVersion - ? name + - "/" + - version + - " (" + - getOS() + - "; " + - (process.isBun - ? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version - : "Node.JS/" + process.version) + - ")" - : name; + ? name + + "/" + + version + + " (" + + getOS() + + "; " + + (process.isBun + ? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version + : "Node.JS/" + process.version) + + ")" + : name; } -module.exports = generateServerString; \ No newline at end of file +module.exports = generateServerString; diff --git a/src/utils/matchHostname.js b/src/utils/matchHostname.js index 5638c07..b2c8c46 100644 --- a/src/utils/matchHostname.js +++ b/src/utils/matchHostname.js @@ -1,24 +1,20 @@ function matchHostname(hostname, reqHostname) { - if (typeof hostname == "undefined" || hostname == "*") { - return true; - } else if ( - reqHostname && - hostname.indexOf("*.") == 0 && - hostname != "*." + if (typeof hostname == "undefined" || hostname == "*") { + return true; + } else if (reqHostname && hostname.indexOf("*.") == 0 && hostname != "*.") { + const hostnamesRoot = hostname.substring(2); + if ( + reqHostname == hostnamesRoot || + (reqHostname.length > hostnamesRoot.length && + reqHostname.indexOf("." + hostnamesRoot) == + reqHostname.length - hostnamesRoot.length - 1) ) { - const hostnamesRoot = hostname.substring(2); - if ( - reqHostname == hostnamesRoot || - (reqHostname.length > hostnamesRoot.length && - reqHostname.indexOf("." + hostnamesRoot) == - reqHostname.length - hostnamesRoot.length - 1) - ) { - return true; - } - } else if (reqHostname && reqHostname == hostname) { - return true; + return true; } - return false; -}; + } else if (reqHostname && reqHostname == hostname) { + return true; + } + return false; +} -module.exports = matchHostname; \ No newline at end of file +module.exports = matchHostname; diff --git a/tests/utils/createRegex.test.js b/tests/utils/createRegex.test.js index 062e921..8209874 100644 --- a/tests/utils/createRegex.test.js +++ b/tests/utils/createRegex.test.js @@ -5,7 +5,7 @@ jest.mock("os", () => ({ platform: jest.fn(), })); -describe("createRegex", () => { +describe("Regular expression creation function", () => { beforeEach(() => { os.platform.mockReset(); }); diff --git a/tests/utils/generateErrorStack.test.js b/tests/utils/generateErrorStack.test.js index 25bd0da..0f14973 100644 --- a/tests/utils/generateErrorStack.test.js +++ b/tests/utils/generateErrorStack.test.js @@ -1,6 +1,6 @@ const generateErrorStack = require("../../src/utils/generateErrorStack"); -describe("generateErrorStack", () => { +describe("Error stack generation function", () => { test("should return the original stack if it is V8-style", () => { const error = new Error("Test error"); error.stack = `Error: Test error diff --git a/tests/utils/ipMatch.test.js b/tests/utils/ipMatch.test.js index f7d317e..f8e8c87 100644 --- a/tests/utils/ipMatch.test.js +++ b/tests/utils/ipMatch.test.js @@ -1,6 +1,6 @@ const ipMatch = require("../../src/utils/ipMatch"); -describe("ipMatch", () => { +describe("IP address matching function", () => { test("should return true if IP1 is empty", () => { expect(ipMatch("", "192.168.1.1")).toBe(true); }); diff --git a/tests/utils/matchHostname.test.js b/tests/utils/matchHostname.test.js index a57537c..173f9ed 100644 --- a/tests/utils/matchHostname.test.js +++ b/tests/utils/matchHostname.test.js @@ -1,51 +1,51 @@ -const matchHostname = require('../../src/utils/matchHostname'); +const matchHostname = require("../../src/utils/matchHostname"); -describe('matchHostname', () => { - test('should return true if hostname is undefined', () => { - expect(matchHostname(undefined, 'example.com')).toBe(true); +describe("Hostname matching function", () => { + test("should return true if hostname is undefined", () => { + expect(matchHostname(undefined, "example.com")).toBe(true); }); test('should return true if hostname is "*"', () => { - expect(matchHostname('*', 'example.com')).toBe(true); + expect(matchHostname("*", "example.com")).toBe(true); }); - test('should return true if reqHostname matches hostname exactly', () => { - expect(matchHostname('example.com', 'example.com')).toBe(true); + test("should return true if reqHostname matches hostname exactly", () => { + expect(matchHostname("example.com", "example.com")).toBe(true); }); - test('should return false if reqHostname does not match hostname exactly', () => { - expect(matchHostname('example.com', 'example.org')).toBe(false); + test("should return false if reqHostname does not match hostname exactly", () => { + expect(matchHostname("example.com", "example.org")).toBe(false); }); test('should return true if hostname starts with "*." and reqHostname matches the root', () => { - expect(matchHostname('*.example.com', 'sub.example.com')).toBe(true); + expect(matchHostname("*.example.com", "sub.example.com")).toBe(true); }); test('should return false if hostname starts with "*." and reqHostname does not match the root', () => { - expect(matchHostname('*.example.com', 'example.org')).toBe(false); + expect(matchHostname("*.example.com", "example.org")).toBe(false); }); test('should return true if hostname starts with "*." and reqHostname is the root', () => { - expect(matchHostname('*.example.com', 'example.com')).toBe(true); + expect(matchHostname("*.example.com", "example.com")).toBe(true); }); test('should return false if hostname is "*."', () => { - expect(matchHostname('*.', 'example.com')).toBe(false); + expect(matchHostname("*.", "example.com")).toBe(false); }); - test('should return false if reqHostname is undefined', () => { - expect(matchHostname('example.com', undefined)).toBe(false); + test("should return false if reqHostname is undefined", () => { + expect(matchHostname("example.com", undefined)).toBe(false); }); test('should return false if hostname does not start with "*." and reqHostname does not match', () => { - expect(matchHostname('sub.example.com', 'example.com')).toBe(false); + expect(matchHostname("sub.example.com", "example.com")).toBe(false); }); test('should return true if hostname starts with "*." and reqHostname matches the root with additional subdomains', () => { - expect(matchHostname('*.example.com', 'sub.sub.example.com')).toBe(true); + expect(matchHostname("*.example.com", "sub.sub.example.com")).toBe(true); }); test('should return false if hostname starts with "*." and reqHostname does not match the root with additional subdomains', () => { - expect(matchHostname('*.example.com', 'sub.sub.example.org')).toBe(false); + expect(matchHostname("*.example.com", "sub.sub.example.org")).toBe(false); }); });