Comparing version 0.2.1 to 0.3.0
@@ -20,3 +20,3 @@ const http = require("http"); | ||
let app = { | ||
use: (middleware, context) => { | ||
use: (middleware, context = {}) => { | ||
middlewares.push({ | ||
@@ -23,0 +23,0 @@ handler: middleware, |
const next = (middlewares, req, res, cb) => { | ||
let middleware = middlewares.shift(); | ||
return () => { | ||
return (err) => { | ||
if (err) return res.send(err); | ||
if (res.statusCode == 200 && !res.finished) { | ||
@@ -9,3 +10,3 @@ if (!middleware) return cb(); | ||
try { | ||
let result = middleware.handler.call(middleware.context || {}, req, res, next(middlewares, req, res, cb)); | ||
let result = middleware.handler.call(middleware.context, req, res, next(middlewares, req, res, cb)); | ||
if (result instanceof Promise) { // async support | ||
@@ -12,0 +13,0 @@ result.catch(res.send); |
@@ -9,3 +9,3 @@ module.exports.send = (req, res) => (data = 200, code = 200, headers = {}) => { | ||
if (data instanceof Error) { | ||
code = data.code || 500; | ||
code = data.status || data.code || 500; | ||
data = { | ||
@@ -30,3 +30,4 @@ code, | ||
req, | ||
data | ||
data, | ||
code | ||
} | ||
@@ -33,0 +34,0 @@ res.emit('response', params); |
{ | ||
"name": "restana", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Super fast and minimalist web framework for building REST micro-services.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -52,3 +52,3 @@ # REST-Ana | ||
``` | ||
Middleware usage: | ||
### Middleware usage: | ||
```js | ||
@@ -75,2 +75,21 @@ const service = require('restana')({}); | ||
service.start(); | ||
``` | ||
``` | ||
Third party middlewares support: | ||
> Almost all middlewares using the *function (req, res, next)* signature format should work. With the consideration that they don't use any custom framework feature. | ||
Examples : | ||
* **raw-body**: [https://www.npmjs.com/package/raw-body](https://www.npmjs.com/package/raw-body). See demo: [raw-body.js](demos/raw-body.js) | ||
* **express-jwt**: [https://www.npmjs.com/package/express-jwt](https://www.npmjs.com/package/express-jwt). See demo: [express-jwt.js](demos/express-jwt.js) | ||
* **body-parser**: [https://www.npmjs.com/package/body-parser](https://www.npmjs.com/package/body-parser). See demo: [body-parser.js](demos/body-parser.js) | ||
## Performance comparison | ||
Performance comparison for a basic *Hello World!* response in cluster mode with 4 processes: | ||
```bash | ||
ab -n 10000 -c 1000 http://localhost:3000/v1/welcome | ||
``` | ||
Results: | ||
* restana: ~1300ms | ||
* koa: ~1500ms | ||
* hapi: ~4200ms | ||
* express: ~1800ms | ||
* restify: ~2000ms |
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
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
9619
151
93