Comparing version 3.0.0 to 3.1.0
23
index.js
const http = require('http') | ||
const httpServer = http.Server | ||
const httpsServer = require('https').Server | ||
@@ -7,8 +9,19 @@ module.exports = (config = {}) => { | ||
server.on('request', (req, res) => { | ||
server instanceof http.Server | ||
? setImmediate(() => router.lookup(req, res)) | ||
: router.lookup(req, res) | ||
}) | ||
config.prioRequestsProcessing = config.prioRequestsProcessing || server instanceof httpServer || server instanceof httpsServer | ||
/* | ||
Native server can also be https server, so we also need to check for it. | ||
Unfortunately, there appears to be no proper way to check for http2 server. | ||
*/ | ||
if (config.prioRequestsProcessing) { | ||
server.on('request', (req, res) => { | ||
setImmediate(() => router.lookup(req, res)) | ||
}) | ||
} else { | ||
server.on('request', (req, res) => { | ||
router.lookup(req, res) | ||
}) | ||
} | ||
return { | ||
@@ -15,0 +28,0 @@ router, |
{ | ||
"name": "0http", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Cero friction HTTP request router. The need for speed!", | ||
@@ -31,8 +31,8 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"find-my-way": "^3.0.1", | ||
"mocha": "^8.1.3", | ||
"body-parser": "^1.19.0", | ||
"chai": "^4.3.0", | ||
"find-my-way": "^3.0.5", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0", | ||
"supertest": "^4.0.2", | ||
"body-parser": "^1.19.0" | ||
"supertest": "^4.0.2" | ||
}, | ||
@@ -39,0 +39,0 @@ "files": [ |
@@ -77,2 +77,3 @@ # 0http | ||
- **errorHandler**: Global error handler function. Default value: | ||
```js | ||
@@ -85,3 +86,6 @@ (err, req, res) => { | ||
* **prioRequestsProcessing**: `true` to use SetImmediate to prioritize router lookup, `false` to disable. By default `true`, if used with native Node.js `http` and `https` servers. Set to `false`, if using Node.js Native Addon server, such as uWebSockets.js, as this will cause a huge performance penalty | ||
Example passing configuration options: | ||
```js | ||
@@ -185,2 +189,3 @@ const sequential = require('0http/lib/router/sequential') | ||
> For more accurate benchmarks please see: | ||
> | ||
> - https://github.com/the-benchmarker/web-frameworks | ||
@@ -187,0 +192,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12918
170
201
2