ultimate-express 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/middlewares.js +3 -2
- package/src/request.js +4 -0
- package/src/response.js +32 -16
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ For full table with other runtimes, check [here](https://github.com/dimdenGD/bun
|
|
|
57
57
|
| express | 10,411.313 | 11,245.57 | 10,598.74 | 9,389.63 |
|
|
58
58
|
|
|
59
59
|
Other benchmarks:
|
|
60
|
-
- [TechEmpower / FrameworkBenchmarks](https://www.techempower.com/benchmarks/#
|
|
60
|
+
- [TechEmpower / FrameworkBenchmarks](https://www.techempower.com/benchmarks/#section=data-r23&test=plaintext&l=zik0sf-pa7)
|
|
61
61
|
- [the-benchmarker / web-frameworks](https://web-frameworks-benchmark.netlify.app/result?l=javascript)
|
|
62
62
|
|
|
63
63
|
### Performance on real-world application
|
package/package.json
CHANGED
package/src/middlewares.js
CHANGED
|
@@ -86,8 +86,9 @@ function static(root, options) {
|
|
|
86
86
|
|
|
87
87
|
if(stat.isDirectory()) {
|
|
88
88
|
if(!req.endsWithSlash) {
|
|
89
|
-
if(options.redirect)
|
|
90
|
-
|
|
89
|
+
if(options.redirect) {
|
|
90
|
+
return res.redirect(301, req._originalPath + '/', true);
|
|
91
|
+
} else {
|
|
91
92
|
if(!options.fallthrough) {
|
|
92
93
|
res.status(404);
|
|
93
94
|
return next(new Error('Not found'));
|
package/src/request.js
CHANGED
package/src/response.js
CHANGED
|
@@ -153,7 +153,7 @@ module.exports = class Response extends Writable {
|
|
|
153
153
|
if (this.chunkedTransfer) {
|
|
154
154
|
this.#pendingChunks.push(chunk);
|
|
155
155
|
const size = this.#pendingChunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);
|
|
156
|
-
const now =
|
|
156
|
+
const now = performance.now();
|
|
157
157
|
// the first chunk is sent immediately (!this.#lastWriteChunkTime)
|
|
158
158
|
// the other chunks are sent when watermark is reached (size >= HIGH_WATERMARK)
|
|
159
159
|
// or if elapsed 50ms of last send (now - this.#lastWriteChunkTime > 50)
|
|
@@ -173,7 +173,7 @@ module.exports = class Response extends Writable {
|
|
|
173
173
|
const size = this.#pendingChunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);
|
|
174
174
|
this._res.write(Buffer.concat(this.#pendingChunks, size));
|
|
175
175
|
this.#pendingChunks = [];
|
|
176
|
-
this.#lastWriteChunkTime = now;
|
|
176
|
+
this.#lastWriteChunkTime = performance.now();
|
|
177
177
|
}
|
|
178
178
|
});
|
|
179
179
|
}, 50);
|
|
@@ -775,28 +775,44 @@ module.exports = class Response extends Writable {
|
|
|
775
775
|
}
|
|
776
776
|
return this.headers['location'] = encodeUrl(path);
|
|
777
777
|
}
|
|
778
|
-
redirect(status, url) {
|
|
778
|
+
redirect(status, url, forceHtml = false) {
|
|
779
779
|
if(typeof status !== 'number' && !url) {
|
|
780
780
|
url = status;
|
|
781
781
|
status = 302;
|
|
782
782
|
}
|
|
783
783
|
this.location(url);
|
|
784
784
|
this.status(status);
|
|
785
|
-
this.headers['content-type'] = 'text/plain; charset=utf-8';
|
|
786
785
|
let body;
|
|
787
786
|
// Support text/{plain,html} by default
|
|
788
|
-
|
|
789
|
-
text
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
body
|
|
798
|
-
|
|
799
|
-
|
|
787
|
+
if(forceHtml) {
|
|
788
|
+
this.set('Content-Type', 'text/html; charset=UTF-8');
|
|
789
|
+
body =
|
|
790
|
+
'<!DOCTYPE html>\n' +
|
|
791
|
+
'<html lang="en">\n' +
|
|
792
|
+
'<head>\n' +
|
|
793
|
+
'<meta charset="utf-8">\n' +
|
|
794
|
+
'<title>Redirecting</title>\n' +
|
|
795
|
+
'</head>\n' +
|
|
796
|
+
'<body>\n' +
|
|
797
|
+
`<pre>Redirecting to ${url.replaceAll("<", "<").replaceAll(">", ">")}</pre>\n` +
|
|
798
|
+
'</body>\n' +
|
|
799
|
+
'</html>\n';
|
|
800
|
+
} else {
|
|
801
|
+
this.format({
|
|
802
|
+
text: () => {
|
|
803
|
+
this.set('Content-Type', 'text/plain; charset=UTF-8');
|
|
804
|
+
body = statuses.message[status] + '. Redirecting to ' + url
|
|
805
|
+
},
|
|
806
|
+
html: () => {
|
|
807
|
+
this.set('Content-Type', 'text/html; charset=UTF-8');
|
|
808
|
+
body = `<p>${statuses.message[status]}. Redirecting to ${url.replaceAll("<", "<").replaceAll(">", ">")}</p>`;
|
|
809
|
+
},
|
|
810
|
+
default: () => {
|
|
811
|
+
this.set('Content-Type', 'text/plain; charset=UTF-8');
|
|
812
|
+
body = '';
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
}
|
|
800
816
|
if (this.req.method === 'HEAD') {
|
|
801
817
|
this.end();
|
|
802
818
|
} else {
|