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

find-my-way

Package Overview
Dependencies
Maintainers
2
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-my-way - npm Package Compare versions

Comparing version 1.16.0 to 1.17.0

test/issue-104.test.js

5

index.d.ts

@@ -117,5 +117,6 @@ import { IncomingMessage, ServerResponse } from 'http';

lookup(
lookup<Context>(
req: V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest,
res: V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse
res: V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse,
ctx?: Context
): void;

@@ -122,0 +123,0 @@

23

index.js

@@ -320,6 +320,8 @@ 'use strict'

Router.prototype.lookup = function lookup (req, res) {
Router.prototype.lookup = function lookup (req, res, ctx) {
var handle = this.find(req.method, sanitizeUrl(req.url), req.headers['accept-version'])
if (handle === null) return this._defaultRoute(req, res)
return handle.handler(req, res, handle.params, handle.store)
if (handle === null) return this._defaultRoute(req, res, ctx)
return ctx === undefined
? handle.handler(req, res, handle.params, handle.store)
: handle.handler.call(ctx, req, res, handle.params, handle.store)
}

@@ -336,2 +338,3 @@

var originalPath = path
var originalPathLength = path.length
var decoded = null

@@ -390,2 +393,10 @@ var pindex = 0

}
if (originalPath.indexOf('/' + previousPath) === -1) {
// we need to know the outstanding path so far from the originalPath since the last encountered "/" and assign it to previousPath.
// e.g originalPath: /aa/bbb/cc, path: bb/cc
// outstanding path: /bbb/cc
var pathDiff = originalPath.slice(0, originalPathLength - pathLen)
previousPath = pathDiff.slice(pathDiff.lastIndexOf('/') + 1, pathDiff.length) + path
}
path = previousPath

@@ -478,5 +489,7 @@ pathLen = previousPath.length

Router.prototype._defaultRoute = function (req, res) {
Router.prototype._defaultRoute = function (req, res, ctx) {
if (this.defaultRoute !== null) {
this.defaultRoute(req, res)
return ctx === undefined
? this.defaultRoute(req, res)
: this.defaultRoute.call(ctx, req, res)
} else {

@@ -483,0 +496,0 @@ res.statusCode = 404

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

const labels = Object.keys(this.children)
var parametricBrother = null
var parametricBrother = this.parametricBrother
for (var i = 0; i < labels.length; i++) {

@@ -76,10 +76,24 @@ const child = this.children[labels[i]]

// Save the parametric brother inside a static children
for (i = 0; i < labels.length; i++) {
const child = this.children[labels[i]]
if (child.kind === this.types.STATIC && parametricBrother) {
child.parametricBrother = parametricBrother
// Save the parametric brother inside static children
const iterate = (node) => {
if (!node) {
return
}
if (node.kind !== this.types.STATIC) {
return
}
if (node !== this) {
node.parametricBrother = parametricBrother
}
const labels = Object.keys(node.children)
for (var i = 0; i < labels.length; i++) {
iterate(node.children[labels[i]])
}
}
iterate(this)
return this

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

{
"name": "find-my-way",
"version": "1.16.0",
"version": "1.17.0",
"description": "Crazy fast http radix based router",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -256,5 +256,5 @@ # find-my-way

<a name="lookup"></a>
#### lookup(request, response)
#### lookup(request, response, [context])
Start a new search, `request` and `response` are the server req/res objects.<br>
If a route is found it will automatically called the handler, otherwise the default route will be called.<br>
If a route is found it will automatically call the handler, otherwise the default route will be called.<br>
The url is sanitized internally, all the parameters and wildcards are decoded automatically.

@@ -265,2 +265,10 @@ ```js

`lookup` accepts an optional context which will be the value of `this` when executing a handler
```js
router.on('GET', '*', function(req, res) {
res.end(this.greeting);
})
router.lookup(req, res, { greeting: 'Hello, World!' })
```
<a name="find"></a>

@@ -267,0 +275,0 @@ #### find(method, path [, version])

@@ -56,2 +56,3 @@ import * as Router from '../..';

http1Router.lookup(http1Req, http1Res);
http1Router.lookup(http1Req, http1Res, {foo: 'bar'});
http1Router.off('GET', '/path');

@@ -112,2 +113,3 @@ http1Router.off(['GET', 'CHECKOUT'], '/path');

http2Router.lookup(http2Req, http2Res);
http2Router.lookup(http2Req, http2Res, {foo: 'bar'});
http2Router.off('GET', '/path');

@@ -114,0 +116,0 @@ http2Router.off(['GET', 'CHECKOUT'], '/path');

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