Socket
Socket
Sign inDemoInstall

router

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

router - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

11

HISTORY.md

@@ -0,1 +1,12 @@

1.2.0 / 2017-02-17
==================
* Skip routing when `req.url` is not set
* deps: debug@2.6.1
- Allow colors in workers
- Deprecated `DEBUG_FD` environment variable set to `3` or higher
- Fix error when running under React Native
- Use same color for same namespace
- deps: ms@0.7.2
1.1.5 / 2017-01-28

@@ -2,0 +13,0 @@ ==================

7

index.js

@@ -372,7 +372,2 @@ /*!

key = keys[i++]
if (!key) {
return done()
}
name = key.name

@@ -579,3 +574,3 @@ paramVal = req.params[name]

function getProtohost(url) {
if (url.length === 0 || url[0] === '/') {
if (typeof url !== 'string' || url.length === 0 || url[0] === '/') {
return undefined

@@ -582,0 +577,0 @@ }

@@ -109,19 +109,17 @@ /*!

Layer.prototype.match = function match(path) {
if (path == null) {
// no path, nothing matches
this.params = undefined
this.path = undefined
return false
}
var match
if (this.regexp.fast_slash) {
// fast path non-ending match for / (everything matches)
this.params = {}
this.path = ''
return true
if (path != null) {
if (this.regexp.fast_slash) {
// fast path non-ending match for / (any path matches)
this.params = {}
this.path = ''
return true
}
// match the path
match = this.regexp.exec(path)
}
var m = this.regexp.exec(path)
if (!m) {
if (!match) {
this.params = undefined

@@ -134,3 +132,3 @@ this.path = undefined

this.params = {}
this.path = m[0]
this.path = match[0]

@@ -141,6 +139,6 @@ // iterate matches

for (var i = 1; i < m.length; i++) {
for (var i = 1; i < match.length; i++) {
var key = keys[i - 1]
var prop = key.name
var val = decode_param(m[i])
var val = decode_param(match[i])

@@ -147,0 +145,0 @@ if (val !== undefined || !(hasOwnProperty.call(params, prop))) {

{
"name": "router",
"description": "Simple middleware-style router",
"version": "1.1.5",
"version": "1.2.0",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",

@@ -10,3 +10,3 @@ "license": "MIT",

"array-flatten": "2.1.1",
"debug": "~2.2.0",
"debug": "2.6.1",
"methods": "~1.1.2",

@@ -20,3 +20,3 @@ "parseurl": "~1.3.1",

"after": "0.8.2",
"finalhandler": "0.5.1",
"finalhandler": "1.0.0",
"istanbul": "0.4.5",

@@ -23,0 +23,0 @@ "mocha": "2.5.3",

@@ -56,4 +56,4 @@ # router

Use the given middleware function for all http methods on the given `path`,
defaulting to the root path.
Use the given [middleware function](#middleware) for all http methods on the
given `path`, defaulting to the root path.

@@ -83,4 +83,4 @@ `router` does not automatically see `use` as a handler. As such, it will not

These are functions which you can directly call on the router to register a new
`handler` for the `method` at a specified `path`.
Method middleware and handlers follow usual [middleware](#middleware) behavior,
except they will only be called when the method and path match the request.

@@ -95,6 +95,6 @@ ```js

Additional middleware may be given before the handler. These middleware behave
exactly as normal with one exception: they may invoke `next('route')`.
Calling `next('route')` bypasses the remaining middleware and handler for this
route, passing the request on to the next route.
[Middleware](#middleware) given before the handler have one additional trick,
they may invoke `next('route')`. Calling `next('route')` bypasses the remaining
middleware and the handler mounted for this route, passing the request to the
next route suitable for handling this request.

@@ -181,2 +181,33 @@ ### router.param(name, param_middleware)

## Middleware
Middleware (and method handlers) are functions that follow specific function
parameters and have defined behavior when used with `router`. The most common
format is with three parameters - "req", "res" and "next".
- `req` - This is a [HTTP incoming message](https://nodejs.org/api/http.html#http_http_incomingmessage) instance.
- `res` - This is a [HTTP server response](https://nodejs.org/api/http.html#http_class_http_serverresponse) instance.
- `next` - Calling this function that tells `router` to proceed to the next matching middleware or method handler. It accepts an error as the first argument.
Middleware and method handlers can also be defined with four arguments. When
the function has four parameters defined, the first argument is an error and
subsequent arguments remain, becoming - "err", "req", "res", "next". These
functions are "error handling middleware", and can be used for handling
errors that occurred in previous handlers (E.g. from calling `next(err)`).
This is most used when you want to define arbitrary rendering of errors.
```js
router.get('/error_route', function (req, res, next) {
return next(new Error('Bad Request'))
})
router.use(function (err, req, res, next) {
res.end(err.message) //=> "Bad Request"
})
```
Error handling middleware will **only** be invoked when an error was given. As
long as the error is in the pipeline, normal middleware and handlers will be
bypassed - only error handling middleware will be invoked with an error.
## Examples

@@ -183,0 +214,0 @@

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