fulmine.js 5.11.0 → 5.11.1

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.
Files changed (2) hide show
  1. package/README.md +33 -0
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -43,6 +43,7 @@ See [Migrating](#migrating) for what it handles and what it deliberately does no
43
43
  - [Difference from similar projects](#difference-from-similar-projects)
44
44
  - [Migrating](#migrating)
45
45
  - [Angular SSR](#angular-ssr)
46
+ - [NestJS](#nestjs)
46
47
  - [When Express is somebody else's dependency](#when-express-is-somebody-elses-dependency)
47
48
  - [Docker](#docker)
48
49
  - [Differences from Express](#differences-from-express)
@@ -172,6 +173,38 @@ that runs on Express and here alike, and the same measurement says a page costs
172
173
  stores only the body makes the server hash the whole document again on every hit, and measures level
173
174
  with no cache at all on the serving side.
174
175
 
176
+ ### NestJS
177
+
178
+ `@nestjs/platform-express` takes an Express instance, so it takes this one, and everything in a Nest
179
+ application keeps working. One line stands between that and the speed: the adapter wraps whatever
180
+ instance it is given in `http.createServer()` and listens on that, which is the shim, so every
181
+ request goes through `node:http` and the application runs at Express's pace. The app here already
182
+ answers as an `http.Server`, so it can be the server rather than being wrapped in one:
183
+
184
+ ```ts
185
+ import { NestFactory } from "@nestjs/core";
186
+ import { ExpressAdapter } from "@nestjs/platform-express";
187
+ import fulmine from "fulmine.js";
188
+
189
+ class FulmineAdapter extends ExpressAdapter {
190
+ initHttpServer() {
191
+ // instead of http.createServer(instance): listen() and close() are then µWS's
192
+ (this as any).httpServer = this.getInstance();
193
+ }
194
+ }
195
+
196
+ const app = await NestFactory.create(AppModule, new FulmineAdapter(fulmine()));
197
+ await app.listen(3000);
198
+ ```
199
+
200
+ Measured on the same Nest application, controllers, pipes and body parsing unchanged: **1.2x on a
201
+ route answering text and 1.9x on one answering JSON with a route parameter**. `app.close()` closes
202
+ the port, as it does on the shim.
203
+
204
+ Two things to know. `forceCloseConnections` has nothing to destroy, since the sockets belong to µWS
205
+ and nothing emits `connection`, and Nest looks at `app.router.stack` to decide whether it has
206
+ already added its body parsers, which is not there, so it adds them once more than it would.
207
+
175
208
  ### When Express is somebody else's dependency
176
209
 
177
210
  A framework built on Express does not `require("express")` in your code, it requires it in its own,
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "fulmine.js",
3
- "version": "5.11.0",
3
+ "version": "5.11.1",
4
4
  "description": "Drop-in Express 5 replacement on uWebSockets.js. Your existing middleware keeps working.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
7
- "fulmine": "src/cli.js",
8
- "fulmine.js": "src/cli.js"
7
+ "fulmine": "src/cli.js"
9
8
  },
10
9
  "scripts": {
11
10
  "test": "node tests/index.js",