ultimate-express 1.2.6 → 1.2.8

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 CHANGED
@@ -34,23 +34,23 @@ Tested using [wrk](https://github.com/wg/wrk) (`-d 60 -t 1 -c 200`). Etag was di
34
34
  | routers/nested-routers (/abccc/nested/ddd) | 10.25k | 50.98k | 1.83 MB/sec | 7.98 MB/sec | **4.97X** |
35
35
  | middlewares/express-static (/static/index.js) | 7.52k | 31.08k | 6.92 MB/sec | 26.48 MB/sec | **4.13X** |
36
36
  | engines/ejs (/test) | 5.92k | 41.64k | 2.40 MB/sec | 16.55 MB/sec | **7.03X** |
37
- | middlewares/body-urlencoded (/abc) | 7.90k | 29.90k | 1.64 MB/sec | 5.36 MB/sec | **3.78X** |
37
+ | middlewares/body-urlencoded (/abc) | 8.01k | 35.10k | 1.66 MB/sec | 7.02 MB/sec | **4.38X** |
38
38
 
39
39
  ### Performance against other frameworks
40
40
 
41
41
  Tested using [bun-http-framework-benchmark](https://github.com/dimdenGD/bun-http-framework-benchmark). This table only includes Node.js results.
42
42
  For full table with other runtimes, check [here](https://github.com/dimdenGD/bun-http-framework-benchmark?tab=readme-ov-file#results).
43
43
 
44
- | Framework | Average | Ping | Query | Body |
45
- | ---------------- | ------- | ---------- | ---------- | ---------- |
46
- | uws | 94,296.49 | 108,551.92 | 104,756.22 | 69,581.33 |
47
- | hyper-express | 66,356.707 | 80,002.53 | 69,953.76 | 49,113.83 |
44
+ | Framework | Average | Ping | Query | Body |
45
+ | -------------------- | ------------- | ------------- | ------------- | ------------- |
46
+ | uws | 94,296.49 | 108,551.92 | 104,756.22 | 69,581.33 |
47
+ | hyper-express | 66,356.707 | 80,002.53 | 69,953.76 | 49,113.83 |
48
48
  | **ultimate-express** | **46,826.31** | **50,764.93** | **49,117.76** | **40,596.24** |
49
- | h3 | 35,423.263 | 41,243.68 | 34,429.26 | 30,596.85 |
50
- | fastify | 33,094.62 | 40,147.67 | 40,076.35 | 19,059.84 |
51
- | hono | 26,576.02 | 36,215.35 | 34,656.12 | 8,856.59 |
52
- | koa | 24,045.08 | 28,202.12 | 24,590.84 | 19,342.28 |
53
- | express | 10,411.313 | 11,245.57 | 10,598.74 | 9,389.63 |
49
+ | h3 | 35,423.263 | 41,243.68 | 34,429.26 | 30,596.85 |
50
+ | fastify | 33,094.62 | 40,147.67 | 40,076.35 | 19,059.84 |
51
+ | hono | 26,576.02 | 36,215.35 | 34,656.12 | 8,856.59 |
52
+ | koa | 24,045.08 | 28,202.12 | 24,590.84 | 19,342.28 |
53
+ | express | 10,411.313 | 11,245.57 | 10,598.74 | 9,389.63 |
54
54
 
55
55
  ### Performance on real-world application
56
56
 
@@ -107,9 +107,11 @@ Optimized routes can be up to 10 times faster than normal routes, as they're usi
107
107
 
108
108
  2. Do not use external `serve-static` module. Instead use built-in `express.static()` middleware, which is optimized for uExpress.
109
109
 
110
- 3. Do not set `body methods` to read body of requests with GET method or other methods that don't need a body. Reading body makes server about 10k req/sec slower.
110
+ 3. Do not use `body-parser` module. Instead use built-in `express.text()`, `express.json()` etc.
111
111
 
112
- 4. By default, µExpress creates 1 (or 0 if your CPU has only 1 core) child thread to improve performance of reading files. You can change this number by setting `threads` to a different number in `express()`, or set to 0 to disable thread pool (`express({ threads: 0 })`). Threads are shared between all express() instances, with largest `threads` number being used. Using more threads will not necessarily improve performance. Sometimes not using threads at all is faster, please [test](https://github.com/wg/wrk/) both options.
112
+ 4. Do not set `body methods` to read body of requests with GET method or other methods that don't need a body. Reading body makes server about 10k req/sec slower.
113
+
114
+ 5. By default, µExpress creates 1 (or 0 if your CPU has only 1 core) child thread to improve performance of reading files. You can change this number by setting `threads` to a different number in `express()`, or set to 0 to disable thread pool (`express({ threads: 0 })`). Threads are shared between all express() instances, with largest `threads` number being used. Using more threads will not necessarily improve performance. Sometimes not using threads at all is faster, please [test](https://github.com/wg/wrk/) both options.
113
115
 
114
116
  ## WebSockets
115
117
 
@@ -281,7 +283,7 @@ In general, basically all features and options are supported. Use [Express 4.x d
281
283
 
282
284
  Most of the middlewares that are compatible with Express are compatible with µExpress. Here's list of middlewares that we test for compatibility:
283
285
 
284
- - ✅ [body-parser](https://npmjs.com/package/body-parser)
286
+ - ✅ [body-parser](https://npmjs.com/package/body-parser) (use `express.text()` etc instead for better performance)
285
287
  - ✅ [cookie-parser](https://npmjs.com/package/cookie-parser)
286
288
  - ✅ [cookie-session](https://npmjs.com/package/cookie-session)
287
289
  - ✅ [serve-static](https://npmjs.com/package/serve-static) (use `express.static()` instead for better performance)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -143,6 +143,9 @@ function createBodyParser(defaultType, beforeReturn) {
143
143
  }
144
144
  if(typeof options.inflate === 'undefined') options.inflate = true;
145
145
  if(typeof options.type === 'string') {
146
+ if(!options.type.includes("*")) {
147
+ options.simpleType = options.type;
148
+ }
146
149
  options.type = [options.type];
147
150
  } else if(typeof options.type !== 'function' && !Array.isArray(options.type)) {
148
151
  throw new Error('type must be a string, function or an array');
@@ -173,13 +176,21 @@ function createBodyParser(defaultType, beforeReturn) {
173
176
  return next(new Error('Request entity too large'));
174
177
  }
175
178
 
176
- if(typeof options.type === 'function') {
177
- if(!options.type(req)) {
179
+ if(options.simpleType) {
180
+ const semicolonIndex = type.indexOf(';');
181
+ const clearType = semicolonIndex !== -1 ? type.substring(0, semicolonIndex) : type;
182
+ if(clearType !== options.simpleType) {
178
183
  return next();
179
184
  }
180
185
  } else {
181
- if(!typeis(req, options.type)) {
182
- return next();
186
+ if(typeof options.type === 'function') {
187
+ if(!options.type(req)) {
188
+ return next();
189
+ }
190
+ } else {
191
+ if(!typeis(req, options.type)) {
192
+ return next();
193
+ }
183
194
  }
184
195
  }
185
196