From 317acff5d66c9236525ad8bbefbd1159cea1bb20 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 19 Oct 2024 07:39:45 +0200 Subject: [PATCH] chore: release SVR.JS 4.1.0 --- src/extraScripts/loghighlight.js | 4 +- src/extraScripts/logviewer.js | 4 +- src/extraScripts/svrpasswd.js | 4 +- src/handlers/serverErrorHandler.js | 2 +- src/index.js | 57 +++++++++++++---- src/middleware/blocklist.js | 2 +- .../nonStandardCodesAndHttpAuthentication.js | 2 +- src/res/statusCodes.js | 63 +++++++++++++++++++ .../{clusterBunShim.js => clusterShim.js} | 10 +-- src/utils/generateServerString.js | 7 ++- src/utils/sendStatistics.js | 12 +++- src/utils/serverconsole.js | 2 +- svrjs.json | 4 +- 13 files changed, 145 insertions(+), 28 deletions(-) rename src/utils/{clusterBunShim.js => clusterShim.js} (96%) diff --git a/src/extraScripts/loghighlight.js b/src/extraScripts/loghighlight.js index b713f9e..dd60393 100644 --- a/src/extraScripts/loghighlight.js +++ b/src/extraScripts/loghighlight.js @@ -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; diff --git a/src/extraScripts/logviewer.js b/src/extraScripts/logviewer.js index f02575e..44e4cb0 100644 --- a/src/extraScripts/logviewer.js +++ b/src/extraScripts/logviewer.js @@ -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; diff --git a/src/extraScripts/svrpasswd.js b/src/extraScripts/svrpasswd.js index 25c6820..f87f7ea 100644 --- a/src/extraScripts/svrpasswd.js +++ b/src/extraScripts/svrpasswd.js @@ -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; diff --git a/src/handlers/serverErrorHandler.js b/src/handlers/serverErrorHandler.js index 94b6cf9..1781e4e 100644 --- a/src/handlers/serverErrorHandler.js +++ b/src/handlers/serverErrorHandler.js @@ -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; diff --git a/src/index.js b/src/index.js index 94f43bd..0f1d155 100644 --- a/src/index.js +++ b/src/index.js @@ -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.versions.bun && - process.versions.bun[0] != "0" && + ((process.isBun && + process.versions.bun && + process.versions.bun[0] != "0") || + (process.versions && process.versions.deno)) && Object.keys(cluster.workers) > 0 ) ) { newWorker = cluster.fork(); } else { - if (SVRJSInitialized) - 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.` - ); + 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) diff --git a/src/middleware/blocklist.js b/src/middleware/blocklist.js index a204d53..258aa29 100644 --- a/src/middleware/blocklist.js +++ b/src/middleware/blocklist.js @@ -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); diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index bf452ef..745cd4c 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -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; diff --git a/src/res/statusCodes.js b/src/res/statusCodes.js index ece40da..df06b36 100644 --- a/src/res/statusCodes.js +++ b/src/res/statusCodes.js @@ -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" }; diff --git a/src/utils/clusterBunShim.js b/src/utils/clusterShim.js similarity index 96% rename from src/utils/clusterBunShim.js rename to src/utils/clusterShim.js index e7c375b..a9b75c4 100644 --- a/src/utils/clusterBunShim.js +++ b/src/utils/clusterShim.js @@ -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 diff --git a/src/utils/generateServerString.js b/src/utils/generateServerString.js index ccd5a74..9e764a9 100644 --- a/src/utils/generateServerString.js +++ b/src/utils/generateServerString.js @@ -7,7 +7,12 @@ function generateServerString(exposeServerVersion) { ? `${name.replace(/ /g, "-")}/${version} (${getOS()}; ${ process.isBun ? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version - : "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, "-"); } diff --git a/src/utils/sendStatistics.js b/src/utils/sendStatistics.js index e502aa8..f7e4e96 100644 --- a/src/utils/sendStatistics.js +++ b/src/utils/sendStatistics.js @@ -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( diff --git a/src/utils/serverconsole.js b/src/utils/serverconsole.js index b5f776e..e89666d 100644 --- a/src/utils/serverconsole.js +++ b/src/utils/serverconsole.js @@ -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; diff --git a/svrjs.json b/svrjs.json index 9134098..c3c945e 100644 --- a/svrjs.json +++ b/svrjs.json @@ -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." ] }