Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restana

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restana - npm Package Compare versions

Comparing version 4.8.1 to 4.9.0

29

libs/request-router.js

@@ -8,3 +8,12 @@ 'use strict'

const methods = require('./methods')
const EventEmitter = require('events')
const BEFORE_ROUTE_REGISTER_EVENT = 'beforeRouteRegister'
function registerRoute ({ routes, service, router, method, args }) {
service.events.emit(BEFORE_ROUTE_REGISTER_EVENT, method, args)
routes.add(`${method.toUpperCase()}${args[0]}`)
router[method].apply(router, args)
}
module.exports = (options, service = {}) => {

@@ -24,2 +33,8 @@ const routes = new Set()

// service events hub
service.events = new EventEmitter({
captureRejections: true
})
service.events.BEFORE_ROUTE_REGISTER = BEFORE_ROUTE_REGISTER_EVENT
// attach use method

@@ -39,13 +54,11 @@ service.use = (...args) => {

// for arch path
args[0].forEach(urlPath => {
const singleRouteArgs = [...argsExceptPath]
singleRouteArgs.unshift(urlPath)
// for each path
args[0].forEach(path => {
const args = [...argsExceptPath]
args.unshift(path)
routes.add(`${method.toUpperCase()}${singleRouteArgs[0]}`)
router[method].apply(router, singleRouteArgs)
registerRoute({ routes, service, router, method, args })
})
} else {
routes.add(`${method.toUpperCase()}${args[0]}`)
router[method].apply(router, args)
registerRoute({ routes, service, router, method, args })
}

@@ -52,0 +65,0 @@

@@ -10,3 +10,3 @@ 'use strict'

const NOOP = () => {}
const NOOP = () => { }

@@ -17,3 +17,3 @@ const stringify = obj => {

const preEnd = (res, contentType, statusCode) => {
const beforeEnd = (res, contentType, statusCode, data) => {
if (contentType) {

@@ -77,3 +77,3 @@ res.setHeader(CONTENT_TYPE_HEADER, contentType)

// NOTE: we exceptionally handle the response termination for streams
preEnd(res, contentType, code)
beforeEnd(res, contentType, code, data)

@@ -97,3 +97,3 @@ data.pipe(res)

preEnd(res, contentType, code)
beforeEnd(res, contentType, code, data)
res.end(data, cb)

@@ -100,0 +100,0 @@ }

{
"name": "restana",
"version": "4.8.1",
"version": "4.9.0",
"description": "Super fast and minimalist web framework for building REST micro-services.",

@@ -41,8 +41,9 @@ "main": "index.js",

"dependencies": {
"0http": "^3.0.0"
"0http": "^3.1.0"
},
"devDependencies": {
"@hapi/hapi": "^20.0.3",
"@hapi/hapi": "^20.1.2",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"body-parser": "^1.19.0",
"chai": "^4.3.4",
"express": "^4.17.1",

@@ -52,6 +53,6 @@ "express-jwt": "^5.3.3",

"http-cache-middleware": "^1.3.6",
"koa": "^2.13.0",
"koa": "^2.13.1",
"koa-router": "^8.0.8",
"microtime": "^3.0.0",
"mocha": "^8.2.1",
"mocha": "^8.3.2",
"morgan": "^1.10.0",

@@ -65,4 +66,4 @@ "muneem": "^2.4.5",

"serve-static": "^1.14.1",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.1",
"socket.io": "^2.4.1",
"socket.io-client": "^2.4.0",
"supertest": "^4.0.2",

@@ -69,0 +70,0 @@ "swagger-tools": "^0.10.4",

@@ -199,6 +199,21 @@ # restana

Some middlewares don't do `return next()`, instead they just call `next()` to finish and continue the remaining middlewares execution. The second, is a bad practice as it silence any potential `Promise` rejection that happens in the downstream middlewares or handlers.
Some middlewares don't call `return next()` inside a synchronous flow. In restana we enable async errors handling by default, however this mechanism fails when a subsequent middleware is just calling `next()` inside a sync or async flow.
In restana (https://github.com/jkyberneees/ana/blob/master/index.js#L99) we enable async errors handling by default, however this mechanism fails when a subsequent middleware is registered containing the mentioned `next()` statement to finish their execution.
Known incompatible middlewares:
- body-parser (https://www.npmjs.com/package/body-parser)
How to bring async chain compatibility to existing middlewares? The `body-parser` example:
```js
const jsonParser = require('body-parser').json()
const service = require('restana')()
service.use((req, res, next) => {
return new Promise(resolve => {
jsonParser(req, res, (err) => {
return resolve(next(err))
})
})
})
```
### Global middlewares

@@ -308,2 +323,9 @@ ```js

```
### Service Events
Service events are accessible through the `service.events` object, an instance of https://nodejs.org/api/events.html
#### Available events
- `service.events.BEFORE_ROUTE_REGISTER`: This event is triggered before registering a route.
## AWS Serverless Integration

@@ -449,7 +471,3 @@ `restana` is compatible with the [serverless-http](https://github.com/dougmoscrop/serverless-http) library, so restana based services can also run as AWS lambdas 🚀

You can support the maintenance of this project:
- Paypal: https://www.paypal.me/kyberneees
- NANO Crypto Coin: `nano_3zm9steh8mb374f8be3rbytqhgzzarczhwtxhihkqt83a4m46oa3xidfiauc`
- XRP Crypto Coin: `rarQgNuiqF9gFLLwd5fdku4jYa9EXpiyCp`
- TRON Crypto Coin: `TJ5Bbf9v4kpptnRsePXYDvnYcYrS5Tyxus`
- BITCOIN Crypto Coin: `bc1qcrr58venyh54ztvkqym39p9rhnxg4308t0802f`
- Ethereum Crypto Coin: `0xD73c8E63a83eBD8Df3fB3d0090f1fe7a1eEB980B`
- PayPal: https://www.paypal.me/kyberneees
- [TRON](https://www.binance.com/en/buy-TRON) Wallet: `TJ5Bbf9v4kpptnRsePXYDvnYcYrS5Tyxus`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc