1
0
Fork 0
forked from svrjs/svrjs

Create config.generateServerString() function and src/utils/generateServerString.js file.

This commit is contained in:
Dorian Niemiec 2024-08-24 17:06:34 +02:00
parent 1a7e602198
commit 1161256ab9
3 changed files with 32 additions and 29 deletions

View file

@ -1,7 +1,8 @@
const http = require("http");
const fs = require("fs");
//const generateErrorStack = require("./utils/generateErrorStack.js");
const getOS = require("./utils/getOS.js");
//const getOS = require("./utils/getOS.js");
const generateServerString = require("./utils/generateServerString.js")
const svrjsInfo = require("../svrjs.json");
const version = svrjsInfo.version;
//const parseURL = require("./utils/urlParser.js");
@ -149,7 +150,7 @@ function requestHandler(req, res) {
logFacilities.errmessage("Stack:");
logFacilities.errmessage(err.stack);
res.writeHead(500, "Internal Server Error", {
Server: (config.exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS")
Server: generateServerString(config.exposeServerVersion)
});
res.end("Error while executing the request handler");
}
@ -158,7 +159,7 @@ function requestHandler(req, res) {
if (res.error) res.error(404);
else {
res.writeHead(404, "Not Found", {
Server: (config.exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS")
Server: generateServerString(config.exposeServerVersion)
});
res.end("Request handler missing");
}

View file

@ -2,9 +2,10 @@ const http = require("http");
const fs = require("fs");
const net = require("net");
const generateErrorStack = require("../utils/generateErrorStack.js");
const generateServerString = require("../utils/generateServerString.js");
const serverHTTPErrorDescs = require("../res/httpErrorDescriptions.js");
const fixNodeMojibakeURL = require("../utils/urlMojibakeFixer.js");
const getOS = require("../utils/getOS.js");
//const getOS = require("../utils/getOS.js");
const ipMatch = require("../utils/ipMatch.js");
const svrjsInfo = require("../../svrjs.json");
const version = svrjsInfo.version;
@ -37,6 +38,11 @@ module.exports = (req, res, logFacilities, config, next) => {
return false;
};
config.generateServerString = () => {
return generateServerString(config.exposeServerVersion);
};
// getCustomHeaders() in SVR.JS 3.x
config.getCustomHeaders = () => {
let ph = Object.assign(config.customHeaders);
if (config.customHeadersVHost) {
@ -63,17 +69,7 @@ module.exports = (req, res, logFacilities, config, next) => {
if (typeof ph[phk] == "string")
ph[phk] = ph[phk].replace(/\{path\}/g, req.url);
});
ph["Server"] = config.exposeServerVersion
? "SVR.JS/" +
version +
" (" +
getOS() +
"; " +
(process.isBun
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
: "Node.JS/" + process.version) +
")"
: "SVR.JS";
ph["Server"] = config.generateServerString();
return ph;
};
@ -588,20 +584,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)

View file

@ -0,0 +1,19 @@
const svrjsInfo = require("../../svrjs.json");
const version = svrjsInfo.version;
const getOS = require("./getOS.js");
function generateServerString(exposeServerVersion) {
return exposeServerVersion
? "SVR.JS/" +
version +
" (" +
getOS() +
"; " +
(process.isBun
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
: "Node.JS/" + process.version) +
")"
: "SVR.JS";
}
module.exports = generateServerString;