1
0
Fork 0
forked from svrjs/svrjs

Update to SVR.JS 3.10.1

This commit is contained in:
Dorian Niemiec 2023-09-12 21:17:24 +02:00
parent ae3cf033be
commit faecaa8b8a
12 changed files with 45 additions and 422 deletions

View file

@ -1 +0,0 @@
0

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>SVR.JS 3.10.0</title>
<title>SVR.JS 3.10.1</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="UTF-8" />
<style>
@ -12,7 +12,7 @@
</style>
</head>
<body>
<h1>Welcome to SVR.JS 3.10.0</h1>
<h1>Welcome to SVR.JS 3.10.1</h1>
<br/>
<img src="/logo.png" style="width: 256px;" />
<br/>
@ -38,7 +38,7 @@
&nbsp;&nbsp;"stackHidden": false,<br/>
&nbsp;&nbsp;"enableRemoteLogBrowsing": false,<br/>
&nbsp;&nbsp;"exposeServerVersion": true,<br/>
&nbsp;&nbsp;"disableServerSideScriptExpose": false,<br/>
&nbsp;&nbsp;"disableServerSideScriptExpose": true,<br/>
&nbsp;&nbsp;"rewriteMap": [<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"definingRegex": "/^\\/serverSideScript\\.js(?:$|[#?])/",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"replacements": [<br/>
@ -117,10 +117,10 @@
</div>
<p>Changes:</p>
<ul>
<li>Added warning about worker count being limited to one when using Bun 1.0 and newer with shimmed (not native) clustering module.</li>
<li>Disabled server-side JavaScript bug workaround for Bun 1.0 and newer (it's not needed anymore for these Bun versions).</li>
<li>Improved clustering shim for Bun.</li>
<li>Improved web root error handling.</li>
<li>Dropped "pretty-bytes" dependency.</li>
<li>Removed undocumented and non-working code.</li>
<li>Fixed bug: .notindex files in directories no longer cause server timeouts, due of non-working undocumented code.</li>
<li>Replaced function converting byte count to human-readable representation with new one.</li>
</ul>
<br/>
<a href="/tests.html">Tests</a><br/>

View file

@ -286,16 +286,6 @@
Run a function exactly one time
</div>
</div>
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
<div style="float: right;">License: MIT</div>
<div style="font-size: 20px;">
<a href="/licenses/pretty-bytes.txt"><b>pretty-bytes</b></a> (by Sindre Sorhus)
</div>
<div style="font-size: 12px;">
Convert bytes to a human readable string: 1337 → 1.34 kB<br/>
<b>Required by SVR.JS.</b>
</div>
</div>
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
<div style="float: right;">License: BSD-3</div>
<div style="font-size: 20px;">

View file

@ -1,9 +0,0 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

66
node_modules/pretty-bytes/index.d.ts generated vendored
View file

@ -1,66 +0,0 @@
declare namespace prettyBytes {
interface Options {
/**
Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
@default false
*/
readonly signed?: boolean;
/**
- If `false`: Output won't be localized.
- If `true`: Localize the output using the system/browser locale.
- If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
__Note:__ Localization should generally work in browsers. Node.js needs to be [built](https://github.com/nodejs/node/wiki/Intl) with `full-icu` or `system-icu`. Alternatively, the [`full-icu`](https://github.com/unicode-org/full-icu-npm) module can be used to provide support at runtime.
@default false
*/
readonly locale?: boolean | string;
/**
Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
@default false
```
import prettyBytes = require('pretty-bytes');
prettyBytes(1337, {bits: true});
//=> '1.34 kbit'
```
*/
readonly bits?: boolean;
}
}
/**
Convert bytes to a human readable string: `1337` `1.34 kB`.
@param number - The number to format.
@example
```
import prettyBytes = require('pretty-bytes');
prettyBytes(1337);
//=> '1.34 kB'
prettyBytes(100);
//=> '100 B'
// Display file size differences
prettyBytes(42, {signed: true});
//=> '+42 B'
// Localized output using German locale
prettyBytes(1337, {locale: 'de'});
//=> '1,34 kB'
```
*/
declare function prettyBytes(
number: number,
options?: prettyBytes.Options
): string;
export = prettyBytes;

76
node_modules/pretty-bytes/index.js generated vendored
View file

@ -1,76 +0,0 @@
'use strict';
const BYTE_UNITS = [
'B',
'kB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
];
const BIT_UNITS = [
'b',
'kbit',
'Mbit',
'Gbit',
'Tbit',
'Pbit',
'Ebit',
'Zbit',
'Ybit'
];
/*
Formats the given number using `Number#toLocaleString`.
- If locale is a string, the value is expected to be a locale-key (for example: `de`).
- If locale is true, the system default locale is used for translation.
- If no value for locale is specified, the number is returned unmodified.
*/
const toLocaleString = (number, locale) => {
let result = number;
if (typeof locale === 'string') {
result = number.toLocaleString(locale);
} else if (locale === true) {
result = number.toLocaleString();
}
return result;
};
module.exports = (number, options) => {
if (!Number.isFinite(number)) {
throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
}
options = Object.assign({bits: false}, options);
const UNITS = options.bits ? BIT_UNITS : BYTE_UNITS;
if (options.signed && number === 0) {
return ' 0 ' + UNITS[0];
}
const isNegative = number < 0;
const prefix = isNegative ? '-' : (options.signed ? '+' : '');
if (isNegative) {
number = -number;
}
if (number < 1) {
const numberString = toLocaleString(number, options.locale);
return prefix + numberString + ' ' + UNITS[0];
}
const exponent = Math.min(Math.floor(Math.log10(number) / 3), UNITS.length - 1);
// eslint-disable-next-line unicorn/prefer-exponentiation-operator
number = Number((number / Math.pow(1000, exponent)).toPrecision(3));
const numberString = toLocaleString(number, options.locale);
const unit = UNITS[exponent];
return prefix + numberString + ' ' + unit;
};

9
node_modules/pretty-bytes/license generated vendored
View file

@ -1,9 +0,0 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,76 +0,0 @@
{
"_from": "pretty-bytes@^5.3.0",
"_id": "pretty-bytes@5.3.0",
"_inBundle": false,
"_integrity": "sha512-hjGrh+P926p4R4WbaB6OckyRtO0F0/lQBiT+0gnxjV+5kjPBrfVBFCsCLbMqVQeydvIoouYTCmmEURiH3R1Bdg==",
"_location": "/pretty-bytes",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "pretty-bytes@^5.3.0",
"name": "pretty-bytes",
"escapedName": "pretty-bytes",
"rawSpec": "^5.3.0",
"saveSpec": null,
"fetchSpec": "^5.3.0"
},
"_requiredBy": [
"/autocannon"
],
"_resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.3.0.tgz",
"_shasum": "f2849e27db79fb4d6cfe24764fc4134f165989f2",
"_spec": "pretty-bytes@^5.3.0",
"_where": "/media/serveradmin/Server/developement/node_modules/autocannon",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/pretty-bytes/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Convert bytes to a human readable string: 1337 → 1.34 kB",
"devDependencies": {
"ava": "^1.4.1",
"full-icu": "^1.2.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"engines": {
"node": ">=6"
},
"files": [
"index.js",
"index.d.ts"
],
"homepage": "https://github.com/sindresorhus/pretty-bytes#readme",
"keywords": [
"pretty",
"bytes",
"byte",
"filesize",
"size",
"file",
"human",
"humanized",
"readable",
"si",
"data",
"locale",
"localization",
"localized"
],
"license": "MIT",
"name": "pretty-bytes",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/pretty-bytes.git"
},
"scripts": {
"test": "xo && NODE_ICU_DATA=node_modules/full-icu ava && tsd"
},
"version": "5.3.0"
}

89
node_modules/pretty-bytes/readme.md generated vendored
View file

@ -1,89 +0,0 @@
# pretty-bytes [![Build Status](https://travis-ci.org/sindresorhus/pretty-bytes.svg?branch=master)](https://travis-ci.org/sindresorhus/pretty-bytes)
> Convert bytes to a human readable string: `1337``1.34 kB`
Useful for displaying file sizes for humans.
*Note that it uses base-10 (e.g. kilobyte).
[Read about the difference between kilobyte and kibibyte.](https://web.archive.org/web/20150324153922/https://pacoup.com/2009/05/26/kb-kb-kib-whats-up-with-that/)*
## Install
```
$ npm install pretty-bytes
```
## Usage
```js
const prettyBytes = require('pretty-bytes');
prettyBytes(1337);
//=> '1.34 kB'
prettyBytes(100);
//=> '100 B'
// Display with units of bits
prettyBytes(1337, {bits: true});
//=> '1.34 kbit'
// Display file size differences
prettyBytes(42, {signed: true});
//=> '+42 B'
// Localized output using German locale
prettyBytes(1337, {locale: 'de'});
//=> '1,34 kB'
```
## API
### prettyBytes(number, [options])
#### number
Type: `number`
The number to format.
#### options
Type: `object`
##### signed
Type: `boolean`<br>
Default: `false`
Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
##### bits
Type: `boolean`<br>
Default: `false`
Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
##### locale
Type: `boolean` `string`<br>
Default: `false` *(No localization)*
- If `true`: Localize the output using the system/browser locale.
- If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
**Note:** Localization should generally work in browsers. Node.js needs to be [built](https://github.com/nodejs/node/wiki/Intl) with `full-icu` or `system-icu`. Alternatively, the [`full-icu`](https://github.com/unicode-org/full-icu-npm) module can be used to provide support at runtime.
## Related
- [pretty-bytes-cli](https://github.com/sindresorhus/pretty-bytes-cli) - CLI for this module
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

74
svr.js
View file

@ -81,7 +81,7 @@ function deleteFolderRecursive(path) {
}
var os = require("os");
var version = "3.10.0";
var version = "3.10.1";
var singlethreaded = false;
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
@ -435,14 +435,6 @@ try {
_errored: err
};
}
var prettyBytes = undefined;
try {
prettyBytes = require("pretty-bytes");
} catch (err) {
prettyBytes = {
_errored: err
};
}
var http2 = {};
try {
http2 = require("http2");
@ -508,31 +500,15 @@ if (!fs.existsSync(__dirname + "/temp")) fs.mkdirSync(__dirname + "/temp");
var modFiles = fs.readdirSync(__dirname + "/mods").sort();
var modInfos = [];
function sizify(x) {
try {
if (prettyBytes._errored) throw prettyBytes._errored;
return prettyBytes(parseInt(x), {
minimumFractionDigits: 0,
maximumFractionDigits: 2
}).replace(/ /g, "").replace(/B/ig, "").replace(/k/g, "K");
} catch (err) {
if (x < 1000) return x.toString();
if (x < 10000) return (Math.round(x / 10) / 100).toString() + "K";
if (x < 100000) return (Math.round(x / 100) / 10).toString() + "K";
if (x < 1000000) return (Math.round(x / 1000)).toString() + "K";
if (x < 10000000) return (Math.round(x / 10000) / 100).toString() + "M";
if (x < 100000000) return (Math.round(x / 100000) / 10).toString() + "M";
if (x < 1000000000) return (Math.round(x / 1000000)).toString() + "M";
if (x < 10000000000) return (Math.round(x / 10000000) / 100).toString() + "G";
if (x < 100000000000) return (Math.round(x / 100000000) / 10).toString() + "G";
if (x < 1000000000000) return (Math.round(x / 1000000000)).toString() + "G";
if (x < 10000000000000) return (Math.round(x / 10000000000) / 100).toString() + "T";
if (x < 100000000000000) return (Math.round(x / 100000000000) / 10).toString() + "T";
if (x < 1000000000000000) return (Math.round(x / 1000000000000)).toString() + "T";
if (x < 10000000000000000) return (Math.round(x / 10000000000000) / 100).toString() + "P";
if (x < 100000000000000000) return (Math.round(x / 100000000000000) / 10).toString() + "P";
return (Math.round(x / 1000000000000000)).toString() + "P";
}
function sizify(bytes) {
if (bytes == 0) return "0";
if (bytes < 0) bytes = -bytes;
var prefixes = ["", "K", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"];
var exponent = Math.floor(Math.log10 ? Math.log10(bytes) : (Math.log(bytes) / Math.log(10)));
var prefixIndex = Math.floor(exponent / 3);
if (prefixIndex >= prefixes.length - 1) prefixIndex = prefixes.length - 1;
var prefixIndexMod = exponent - (prefixIndex * 3);
return (Math.round(bytes / Math.pow(10, Math.max(0, exponent - Math.max(2, prefixIndexMod)))) / (exponent > 2 ? Math.pow(10, Math.max(0, 2 - prefixIndexMod)) : 1)).toString() + prefixes[prefixIndex];
}
function getOS() {
@ -3356,15 +3332,7 @@ if (!cluster.isPrimary) {
return;
}
if (version.indexOf("Nightly-") === 0 && (href == "/invoke500.svr" || (os.platform() == "win32" && href.toLowerCase() == "/invoke500.svr"))) {
if (uobject.query.crash !== undefined) throw new Error("Intentionally crashed");
try {
throw new Error("This page is intended to return 500 code.");
} catch (err) {
callServerError(500, undefined, generateErrorStack(err));
return;
}
} else if (allowStatus && (href == "/svrjsstatus.svr" || (os.platform() == "win32" && href.toLowerCase() == "/svrjsstatus.svr"))) {
if (allowStatus && (href == "/svrjsstatus.svr" || (os.platform() == "win32" && href.toLowerCase() == "/svrjsstatus.svr"))) {
function formatRelativeTime(relativeTime) {
var days = Math.floor(relativeTime / 60 / (60 * 24));
var dateDiff = new Date(relativeTime * 1000);
@ -3375,10 +3343,6 @@ if (!cluster.isPrimary) {
res.writeHead(200, "OK", hdhds);
res.end((head == "" ? "<html><head><title>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /></head><body>" : head.replace(/<head>/i, "<head><title>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</title>")) + "<h1>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</h1>Server version: " + (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS") + "<br/><hr/>Current time: " + new Date().toString() + "<br/>Thread start time: " + new Date(new Date() - (process.uptime() * 1000)).toString() + "<br/>Thread uptime: " + formatRelativeTime(Math.floor(process.uptime())) + "<br/>OS uptime: " + formatRelativeTime(os.uptime()) + "<br/>Total request count: " + reqcounter + "<br/>Average request rate: " + (Math.round((reqcounter / process.uptime()) * 100) / 100) + " requests/s" + (process.memoryUsage ? ("<br/>Memory usage of thread: " + sizify(process.memoryUsage().rss) + "B") : "") + (process.cpuUsage ? ("<br/>Total CPU usage by thread: u" + (process.cpuUsage().user / 1000) + "ms s" + (process.cpuUsage().system / 1000) + "ms - " + (Math.round((((process.cpuUsage().user + process.cpuUsage().system) / 1000000) / process.uptime()) * 1000) / 1000) + "%") : "") + "<br/>Thread PID: " + process.pid + "<br/>" + (foot == "" ? "</body></html>" : foot));
return;
} else if (version.indexOf("Nightly-") === 0 && (href == "/crash.svr" || (os.platform() == "win32" && href.toLowerCase() == "/crash.svr"))) {
process.nextTick(function () {
throw new Error("Intentionally crashed");
});
}
/////////////////////////////////////////////
@ -3432,21 +3396,19 @@ if (!cluster.isPrimary) {
// Check if index file exists
if (req.url == "/" || stats.isDirectory()) {
fs.stat(readFrom + "/.notindex".replace(/\/+/g, "/"), function (e) {
if (e) {
fs.stat((readFrom + "/index.html").replace(/\/+/g, "/"), function (e, s) {
if (e || !s.isFile()) {
fs.stat((readFrom + "/index.htm").replace(/\/+/g, "/"), function (e, s) {
if (e || !s.isFile()) {
fs.stat((readFrom + "/index.xhtml").replace(/\/+/g, "/"), function (e, s) {
if (e || !s.isFile()) {
properDirectoryListingServe();
properDirectoryListingAndStaticFileServe();
} else {
stats = s;
pth = (pth + "/index.xhtml").replace(/\/+/g, "/");
ext = "xhtml";
readFrom = "./" + pth;
properDirectoryListingServe();
properDirectoryListingAndStaticFileServe();
}
});
} else {
@ -3454,7 +3416,7 @@ if (!cluster.isPrimary) {
pth = (pth + "/index.htm").replace(/\/+/g, "/");
ext = "htm";
readFrom = "./" + pth;
properDirectoryListingServe();
properDirectoryListingAndStaticFileServe();
}
});
} else {
@ -3462,16 +3424,14 @@ if (!cluster.isPrimary) {
pth = (pth + "/index.html").replace(/\/+/g, "/");
ext = "html";
readFrom = "./" + pth;
properDirectoryListingServe();
}
});
properDirectoryListingAndStaticFileServe();
}
});
} else {
properDirectoryListingServe();
properDirectoryListingAndStaticFileServe();
}
function properDirectoryListingServe() {
function properDirectoryListingAndStaticFileServe() {
if (stats.isDirectory()) {
// Check if directory listing is enabled in the configuration
if (checkForEnabledDirectoryListing(req.headers.host)) {

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>SVR.JS 3.10.0 Tests</title>
<title>SVR.JS 3.10.1 Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="UTF-8" />
<style>
@ -12,7 +12,7 @@
</style>
</head>
<body>
<h1>SVR.JS 3.10.0 Tests</h1>
<h1>SVR.JS 3.10.1 Tests</h1>
<h2>Directory</h2>
<iframe src="/testdir" width="50%" height="300px"></iframe>
<h2>Directory (with query)</h2>

View file

@ -1 +0,0 @@
1