fulmine.js 5.19.2 → 5.19.3
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/package.json +2 -1
- package/src/adopt.js +20 -26
- package/src/application.js +46 -45
- package/src/cli.js +28 -34
- package/src/cluster.js +16 -25
- package/src/compression.js +39 -51
- package/src/declarative.js +586 -538
- package/src/hot-settings.js +80 -0
- package/src/index.js +11 -17
- package/src/lazy-readable.js +129 -0
- package/src/lazy-writable.js +97 -0
- package/src/middlewares.js +61 -77
- package/src/nest.js +19 -34
- package/src/node-shim.js +11 -13
- package/src/optimizer.js +598 -0
- package/src/parse-query.js +3 -3
- package/src/request-utils.js +306 -0
- package/src/request.js +101 -513
- package/src/response-utils.js +88 -0
- package/src/response.js +100 -443
- package/src/route.js +4 -5
- package/src/router-utils.js +950 -0
- package/src/router.js +126 -2148
- package/src/server-shape.js +26 -41
- package/src/server-timing.js +16 -29
- package/src/socket.js +208 -0
- package/src/testing.js +39 -42
- package/src/usage.js +16 -21
- package/src/utils.js +49 -59
- package/src/verify.js +18 -28
- package/src/view.js +5 -7
- package/src/walk.js +580 -0
- package/src/websocket.js +19 -20
- package/src/work.js +21 -27
package/src/nest.js
CHANGED
|
@@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
// require("fulmine.js/nest"): the Nest HTTP adapter, so a Nest application runs on
|
|
18
|
-
// anyone having to write this file themselves.
|
|
17
|
+
// require("fulmine.js/nest"): the Nest HTTP adapter, so a Nest application runs on uWS.
|
|
19
18
|
//
|
|
20
19
|
// import { NestFactory } from "@nestjs/core";
|
|
21
20
|
// import { FulmineExpressAdapter } from "fulmine.js/nest";
|
|
@@ -23,24 +22,17 @@ limitations under the License.
|
|
|
23
22
|
// const app = await NestFactory.create(AppModule, new FulmineExpressAdapter());
|
|
24
23
|
// await app.listen(3000);
|
|
25
24
|
//
|
|
26
|
-
// @nestjs/platform-express takes any Express instance
|
|
27
|
-
//
|
|
28
|
-
// and they are the whole reason this file exists:
|
|
25
|
+
// @nestjs/platform-express takes any Express instance and this is one, so controllers, pipes,
|
|
26
|
+
// guards and interceptors are untouched. Only three methods below the adapter need overriding:
|
|
29
27
|
//
|
|
30
|
-
// - initHttpServer wraps the instance in http.createServer()
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
// -
|
|
35
|
-
//
|
|
36
|
-
// rather than kept as layers, so the answer was always "no" and a second call added a second
|
|
37
|
-
// pair. It is remembered here instead, which is the same answer by a different route.
|
|
38
|
-
// - httpsOptions asks node to make a TLS server out of the instance. TLS here belongs to µWS and
|
|
39
|
-
// is configured when the app is built, so that combination is refused with the line to write
|
|
40
|
-
// rather than silently starting a plaintext server.
|
|
28
|
+
// - initHttpServer wraps the instance in http.createServer(). That would push every request
|
|
29
|
+
// through node's parser and node-shim.js, the slow path. The app is already an http.Server.
|
|
30
|
+
// - registerParserMiddleware looks for Nest's body parsers in app.router.stack. There is no
|
|
31
|
+
// layer array here, so the answer was always "no" and a second call added a second pair.
|
|
32
|
+
// - httpsOptions asks node for a TLS server. TLS belongs to uWS and is set when the app is
|
|
33
|
+
// built, so that combination is refused.
|
|
41
34
|
//
|
|
42
|
-
// @nestjs/platform-express is an optional peer dependency
|
|
43
|
-
// it, and nothing loads this file unless you ask for it by name.
|
|
35
|
+
// @nestjs/platform-express is an optional peer dependency, only this file requires it.
|
|
44
36
|
|
|
45
37
|
"use strict";
|
|
46
38
|
|
|
@@ -48,10 +40,10 @@ const { ExpressAdapter } = require("@nestjs/platform-express");
|
|
|
48
40
|
const fulmine = require("./index.js");
|
|
49
41
|
|
|
50
42
|
/**
|
|
51
|
-
* Nest's Express adapter, listening on
|
|
43
|
+
* Nest's Express adapter, listening on uWebSockets.js instead of node.
|
|
52
44
|
*
|
|
53
|
-
* Pass a configured app when you need one, `new FulmineExpressAdapter(fulmine({ uwsOptions }))
|
|
54
|
-
*
|
|
45
|
+
* Pass a configured app when you need one, `new FulmineExpressAdapter(fulmine({ uwsOptions }))`.
|
|
46
|
+
* With no argument it builds a default one, like `new ExpressAdapter()`.
|
|
55
47
|
*/
|
|
56
48
|
class FulmineExpressAdapter extends ExpressAdapter {
|
|
57
49
|
/**
|
|
@@ -60,8 +52,7 @@ class FulmineExpressAdapter extends ExpressAdapter {
|
|
|
60
52
|
constructor(instance) {
|
|
61
53
|
super(instance || fulmine());
|
|
62
54
|
/**
|
|
63
|
-
*
|
|
64
|
-
* has and this does not. See registerParserMiddleware below.
|
|
55
|
+
* Stands in for the layer array Express has. See registerParserMiddleware below.
|
|
65
56
|
* @type {boolean}
|
|
66
57
|
*/
|
|
67
58
|
this._parsersRegistered = false;
|
|
@@ -84,10 +75,7 @@ class FulmineExpressAdapter extends ExpressAdapter {
|
|
|
84
75
|
this.httpServer = this.getInstance();
|
|
85
76
|
if (options?.forceCloseConnections) {
|
|
86
77
|
// trackOpenConnections() listens for 'connection', which nothing emits: the sockets
|
|
87
|
-
// belong to
|
|
88
|
-
// quietly waits forever for what it thinks it can destroy is worse than one that does
|
|
89
|
-
// not offer to. Through Nest's own logger, so the line arrives where every other line
|
|
90
|
-
// from the framework does; it is private in the typings and inherited all the same
|
|
78
|
+
// belong to uWS. Warned through Nest's own logger, private in the typings but there
|
|
91
79
|
/** @type {any} */ (this).logger.warn(
|
|
92
80
|
"forceCloseConnections has no effect on fulmine.js: the sockets belong to µWS. " +
|
|
93
81
|
"app.close() stops accepting and waits for the requests in flight; an idle keep-alive " +
|
|
@@ -97,11 +85,9 @@ class FulmineExpressAdapter extends ExpressAdapter {
|
|
|
97
85
|
}
|
|
98
86
|
|
|
99
87
|
/**
|
|
100
|
-
* Nest's json and urlencoded parsers, added once however often this is called.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* handler is named `jsonParser` or `urlencodedParser`. There is no such array here, so the scan
|
|
104
|
-
* answered no every time and a second call put a second pair in front of every request.
|
|
88
|
+
* Nest's json and urlencoded parsers, added once however often this is called. Express looks
|
|
89
|
+
* for them in `app.router.stack`; there is no such array here, so a second call was putting a
|
|
90
|
+
* second pair in front of every request.
|
|
105
91
|
*
|
|
106
92
|
* @param {string} [prefix]
|
|
107
93
|
* @param {boolean} [rawBody]
|
|
@@ -114,6 +100,5 @@ class FulmineExpressAdapter extends ExpressAdapter {
|
|
|
114
100
|
}
|
|
115
101
|
}
|
|
116
102
|
|
|
117
|
-
// a named export
|
|
118
|
-
// is how @nestjs/platform-express exports ExpressAdapter too
|
|
103
|
+
// a named export, the way @nestjs/platform-express exports ExpressAdapter
|
|
119
104
|
module.exports = { FulmineExpressAdapter };
|
package/src/node-shim.js
CHANGED
|
@@ -15,12 +15,12 @@ limitations under the License.
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// A uWS-shaped request and response backed by node's own, so an app can serve what arrived through
|
|
18
|
-
// http.createServer. Nothing
|
|
19
|
-
//
|
|
18
|
+
// http.createServer. Nothing here is fast and it does not need to be: it is what makes supertest
|
|
19
|
+
// and http.createServer(app) work.
|
|
20
20
|
//
|
|
21
|
-
// Request and Response ask uWS for eighteen things and this answers all eighteen. Where the
|
|
22
|
-
//
|
|
23
|
-
//
|
|
21
|
+
// Request and Response ask uWS for eighteen things and this answers all eighteen. Where the models
|
|
22
|
+
// disagree node's gives way: cork only runs its callback, and a status is remembered rather than
|
|
23
|
+
// sent, since node writes the head with the first byte of body.
|
|
24
24
|
|
|
25
25
|
const { IncomingMessage } = require("http");
|
|
26
26
|
|
|
@@ -92,9 +92,8 @@ function toArrayBuffer(chunk) {
|
|
|
92
92
|
/**
|
|
93
93
|
* What uWS calls an HttpRequest, over node's IncomingMessage.
|
|
94
94
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* cannot tell which kind of request it is holding.
|
|
95
|
+
* Valid as long as the response is, which is longer than uWS allows: node keeps the headers alive.
|
|
96
|
+
* Request copies them anyway, since it cannot tell which kind of request it is holding.
|
|
98
97
|
*/
|
|
99
98
|
class NodeHttpRequest {
|
|
100
99
|
/** @param {import("http").IncomingMessage} req */
|
|
@@ -162,9 +161,8 @@ class NodeHttpRequest {
|
|
|
162
161
|
/**
|
|
163
162
|
* What uWS calls an HttpResponse, over node's ServerResponse.
|
|
164
163
|
*
|
|
165
|
-
* The status and the headers are held until node writes the head
|
|
166
|
-
*
|
|
167
|
-
* the headers too, before the ones still to come had been set.
|
|
164
|
+
* The status and the headers are held until node writes the head, which it does with the first byte
|
|
165
|
+
* of body. So writeStatus only remembers: sending it here would send the headers too early.
|
|
168
166
|
*/
|
|
169
167
|
class NodeHttpResponse {
|
|
170
168
|
/**
|
|
@@ -391,7 +389,7 @@ class NodeHttpResponse {
|
|
|
391
389
|
|
|
392
390
|
/**
|
|
393
391
|
* Whether these are node's own request and response rather than this project's.
|
|
394
|
-
* @param {any} req
|
|
392
|
+
* @param {any} req anything a caller handed the router, which is the point of the check
|
|
395
393
|
*/
|
|
396
394
|
function isNodeRequest(req) {
|
|
397
395
|
return req instanceof IncomingMessage;
|
|
@@ -400,7 +398,7 @@ function isNodeRequest(req) {
|
|
|
400
398
|
/**
|
|
401
399
|
* Serves a request that arrived through node's HTTP server with the given router or app.
|
|
402
400
|
*
|
|
403
|
-
* @param {any} router
|
|
401
|
+
* @param {any} router the router or application serving this request
|
|
404
402
|
* @param {import("http").IncomingMessage} nodeReq
|
|
405
403
|
* @param {import("http").ServerResponse} nodeRes
|
|
406
404
|
* @param {(err?: any) => void} [next] called when nothing in the router answered
|