1
0
Fork 0
forked from svrjs/svrjs

chore: release SVR.JS 4.1.0

This commit is contained in:
Dorian Niemiec 2024-10-19 07:39:45 +02:00
parent f4fc6ba165
commit 317acff5d6
13 changed files with 145 additions and 28 deletions

View file

@ -5,7 +5,9 @@ const readline = require("readline");
const args = process.argv;
for (
let i =
process.argv[0].indexOf("node") > -1 || process.argv[0].indexOf("bun") > -1
process.argv[0].indexOf("node") > -1 ||
process.argv[0].indexOf("bun") > -1 ||
process.argv[0].indexOf("deno") > -1
? 2
: 1;
i < args.length;

View file

@ -6,7 +6,9 @@ const readline = require("readline");
const args = process.argv;
for (
let i =
process.argv[0].indexOf("node") > -1 || process.argv[0].indexOf("bun") > -1
process.argv[0].indexOf("node") > -1 ||
process.argv[0].indexOf("bun") > -1 ||
process.argv[0].indexOf("deno") > -1
? 2
: 1;
i < args.length;

View file

@ -299,7 +299,9 @@ if (
args.push("-h");
for (
let i =
process.argv[0].indexOf("node") > -1 || process.argv[0].indexOf("bun") > -1
process.argv[0].indexOf("node") > -1 ||
process.argv[0].indexOf("bun") > -1 ||
process.argv[0].indexOf("deno") > -1
? 2
: 1;
i < args.length;

View file

@ -1,5 +1,5 @@
const os = require("os");
const cluster = require("../utils/clusterBunShim.js");
const cluster = require("../utils/clusterShim.js");
const serverErrorDescs = require("../res/serverErrorDescriptions.js");
let serverconsole = {};
let attmts = 5;

View file

@ -138,7 +138,9 @@ let disableMods = false;
const args = process.argv;
for (
let i =
process.argv[0].indexOf("node") > -1 || process.argv[0].indexOf("bun") > -1
process.argv[0].indexOf("node") > -1 ||
process.argv[0].indexOf("bun") > -1 ||
process.argv[0].indexOf("deno") > -1
? 2
: 1;
i < args.length;
@ -197,7 +199,7 @@ if (!fs.existsSync(process.dirname + "/mods"))
if (!fs.existsSync(process.dirname + "/temp"))
fs.mkdirSync(process.dirname + "/temp");
const cluster = require("./utils/clusterBunShim.js"); // Cluster module with shim for Bun
const cluster = require("./utils/clusterShim.js"); // Cluster module with shim for Bun and Deno
const legacyModWrapper = require("./utils/legacyModWrapper.js");
const generateErrorStack = require("./utils/generateErrorStack.js");
const {
@ -631,6 +633,7 @@ try {
}
if (vnum === undefined) vnum = 0;
if (process.versions && process.versions.deno) vnum = 64;
if (process.isBun) vnum = 64;
let mods = [];
@ -1416,27 +1419,51 @@ function SVRJSFork() {
serverconsole.locwarnmessage(
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`
);
} else if (
!threadLimitWarned &&
cluster.__shimmed__ &&
process.versions &&
process.versions.deno
) {
threadLimitWarned = true;
serverconsole.locwarnmessage(
`${name} limited the number of workers to one, because of startup problems in Deno with shimmed (not native) clustering module. Reliability may suffer.`
);
}
if (
!(
cluster.__shimmed__ &&
process.isBun &&
((process.isBun &&
process.versions.bun &&
process.versions.bun[0] != "0" &&
process.versions.bun[0] != "0") ||
(process.versions && process.versions.deno)) &&
Object.keys(cluster.workers) > 0
)
) {
newWorker = cluster.fork();
} else {
if (SVRJSInitialized)
if (SVRJSInitialized) {
if (
process.isBun &&
process.versions.bun &&
process.versions.bun[0] != "0"
)
serverconsole.locwarnmessage(
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`
);
else if (process.versions && process.versions.deno)
serverconsole.locwarnmessage(
`${name} limited the number of workers to one, because of startup problems in Deno with shimmed (not native) clustering module. Reliability may suffer.`
);
}
}
} catch (err) {
if (err.name == "NotImplementedError") {
if (
err.name == "NotImplementedError" ||
err.message == "Not implemented: cluster.fork"
) {
// If cluster.fork throws a NotImplementedError, shim cluster module
cluster.bunShim();
cluster.shim();
if (
!threadLimitWarned &&
cluster.__shimmed__ &&
@ -1710,6 +1737,10 @@ function start(init) {
serverconsole.locwarnmessage(
"PBKDF2 password hashing function in Bun versions older than v1.1.13 blocks the event loop, which may result in denial of service."
);
} else if (process.versions && process.versions.deno) {
serverconsole.locwarnmessage(
`Deno support is experimental. Some features of ${name}, ${name} mods and ${name} server-side JavaScript may not work as expected.`
);
}
if (cluster.isPrimary === undefined)
serverconsole.locwarnmessage(
@ -1725,6 +1756,7 @@ function start(init) {
);
if (
!process.isBun &&
!(process.versions && process.versions.deno) &&
/^v(?:[0-9]\.|1[0-7]\.|18\.(?:[0-9]|1[0-8])\.|18\.19\.0|20\.(?:[0-9]|10)\.|20\.11\.0|21\.[0-5]\.|21\.6\.0|21\.6\.1(?![0-9]))/.test(
process.version
)
@ -1734,6 +1766,7 @@ function start(init) {
);
if (
!process.isBun &&
!(process.versions && process.versions.deno) &&
/^v(?:[0-9]\.|1[0-7]\.|18\.(?:1?[0-9])\.|18\.20\.0|20\.(?:[0-9]|1[01])\.|20\.12\.0|21\.[0-6]\.|21\.7\.0|21\.7\.1(?![0-9]))/.test(
process.version
)
@ -1805,6 +1838,8 @@ function start(init) {
serverconsole.locmessage("Server version: " + version);
if (process.isBun)
serverconsole.locmessage("Bun version: v" + process.versions.bun);
else if (process.versions && process.versions.deno)
serverconsole.locmessage("Deno version: " + process.versions.deno);
else serverconsole.locmessage("Node.JS version: " + process.version);
const CPUs = os.cpus();
if (CPUs.length > 0)

View file

@ -1,4 +1,4 @@
const cluster = require("../utils/clusterBunShim.js");
const cluster = require("../utils/clusterShim.js");
const ipBlockList = require("../utils/ipBlockList.js");
let blocklist = ipBlockList(process.serverConfig.blacklist);

View file

@ -4,7 +4,7 @@ const createRegex = require("../utils/createRegex.js");
const ipMatch = require("../utils/ipMatch.js");
const matchHostname = require("../utils/matchHostname.js");
const ipBlockList = require("../utils/ipBlockList.js");
const cluster = require("../utils/clusterBunShim.js");
const cluster = require("../utils/clusterShim.js");
const svrjsInfo = require("../../svrjs.json");
const { name } = svrjsInfo;

View file

@ -2,7 +2,70 @@ const http = require("http");
const statusCodes = {
...http.STATUS_CODES,
100: "Continue",
101: "Switching Protocols",
102: "Processing",
103: "Early Hints",
200: "OK",
201: "Created",
202: "Accepted",
203: "Non-Authoritative Information",
204: "No Content",
205: "Reset Content",
206: "Partial Content",
207: "Multi-Status",
208: "Already Reported",
226: "IM Used",
300: "Multiple Choices",
301: "Moved Permanently",
302: "Found",
303: "See Other",
304: "Not Modified",
305: "Use Proxy",
307: "Temporary Redirect",
308: "Permanent Redirect",
400: "Bad Request",
401: "Unauthorized",
402: "Payment Required",
403: "Forbidden",
404: "Not Found",
405: "Method Not Allowed",
406: "Not Acceptable",
407: "Proxy Authentication Required",
408: "Request Timeout",
409: "Conflict",
410: "Gone",
411: "Length Required",
412: "Precondition Failed",
413: "Payload Too Large",
414: "URI Too Long",
415: "Unsupported Media Type",
416: "Range Not Satisfiable",
417: "Expectation Failed",
418: "I'm a Teapot",
421: "Misdirected Request",
422: "Unprocessable Entity",
423: "Locked",
424: "Failed Dependency",
425: "Too Early",
426: "Upgrade Required",
428: "Precondition Required",
429: "Too Many Requests",
431: "Request Header Fields Too Large",
451: "Unavailable For Legal Reasons",
497: "HTTP Request Sent to HTTPS Port",
500: "Internal Server Error",
501: "Not Implemented",
502: "Bad Gateway",
503: "Service Unavailable",
504: "Gateway Timeout",
505: "HTTP Version Not Supported",
506: "Variant Also Negotiates",
507: "Insufficient Storage",
508: "Loop Detected",
509: "Bandwidth Limit Exceeded",
510: "Not Extended",
511: "Network Authentication Required",
598: "Network Read Timeout Error",
599: "Network Connect Timeout Error"
};

View file

@ -13,9 +13,9 @@ if (!process.singleThreaded) {
// Clustering is not supported!
}
// Cluster & IPC shim for Bun
// Cluster & IPC shim for Bun and Deno
cluster.bunShim = () => {
cluster.shim = () => {
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
cluster.isPrimary = cluster.isMaster;
cluster.isWorker = !cluster.isMaster;
@ -126,7 +126,7 @@ if (!process.singleThreaded) {
};
try {
worker.send(undefined);
if (process.isBun) worker.send(undefined);
} catch (err) {
if (err.message === "NOT IMPLEMENTED") {
sendImplemented = false;
@ -216,11 +216,11 @@ if (!process.singleThreaded) {
};
if (
process.isBun &&
(process.isBun || (process.versions && process.versions.deno)) &&
(cluster.isMaster === undefined ||
(cluster.isMaster && process.env.NODE_UNIQUE_ID))
) {
cluster.bunShim();
cluster.shim();
}
// Shim cluster.isPrimary field

View file

@ -7,6 +7,11 @@ function generateServerString(exposeServerVersion) {
? `${name.replace(/ /g, "-")}/${version} (${getOS()}; ${
process.isBun
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
: process.versions && process.versions.deno
? "Deno/v" +
process.versions.deno +
"; like Node.JS/" +
process.version
: "Node.JS/" + process.version
})`
: name.replace(/ /g, "-");

View file

@ -28,8 +28,16 @@ try {
function sendStatistics(modInfos, callback) {
const statisticsToSend = JSON.stringify({
version: version,
runtime: process.isBun ? "Bun" : "Node.js",
runtimeVersion: process.isBun ? process.versions.bun : process.version,
runtime: process.isBun
? "Bun"
: process.versions && process.versions.deno
? "Deno"
: "Node.js",
runtimeVersion: process.isBun
? process.versions.bun
: process.versions && process.versions.deno
? process.versions.deno
: process.version,
mods: modInfos
});
const statisticsRequest = https.request(

View file

@ -3,7 +3,7 @@ const fs = require("fs");
let enableLoggingIntoFile = process.serverConfig.enableLogging;
let logFile = undefined;
let logSync = false;
let cluster = require("./clusterBunShim.js");
let cluster = require("./clusterShim.js");
let reallyExiting = false;
const timestamp = process.serverConfig.timestamp;

View file

@ -1,9 +1,9 @@
{
"version": "4.0.2",
"version": "4.1.0",
"name": "SVR.JS",
"documentationURL": "https://svrjs.org/docs",
"statisticsServerCollectEndpoint": "https://statistics.svrjs.org/collect.svr",
"changes": [
"Fixed a bug with 497, 598, and 599 status code HTTP responses."
"Added experimental support for Deno 2."
]
}