Socket
Socket
Sign inDemoInstall

koa-router

Package Overview
Dependencies
Maintainers
2
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-router - npm Package Compare versions

Comparing version 11.0.0 to 11.0.1

52

lib/router.js

@@ -51,2 +51,3 @@ /**

* @param {String=} opts.prefix prefix router paths
* @param {String|RegExp=} opts.host host for router match
* @constructor

@@ -72,2 +73,3 @@ */

this.stack = [];
this.host = this.opts.host;
}

@@ -188,2 +190,20 @@

*
*
* ### Match host for each router instance
*
* ```javascript
* const router = new Router({
* host: 'example.domain' // only match if request host exactly equal `example.domain`
* });
*
* ```
*
* OR host cloud be a regexp
*
* ```javascript
* const router = new Router({
* host: /.*\.?example\.domain$/ // all host end with .example.domain would be matched
* });
* ```
*
* @name get|put|post|patch|delete|del

@@ -364,2 +384,8 @@ * @memberof module:koa-router.prototype

const hostMatched = router.matchHost(ctx.host);
if (!hostMatched) {
return next();
}
const path = router.opts.routerPath || ctx.routerPath || ctx.path;

@@ -743,2 +769,28 @@ const matched = router.match(path, ctx.method);

/**
* Match given `input` to allowed host
* @param {String} input
* @returns {boolean}
*/
Router.prototype.matchHost = function (input) {
const { host } = this;
if (!host) {
return true;
}
if (!input) {
return false;
}
if (typeof host === 'string') {
return input === host;
}
if (typeof host === 'object' && host instanceof RegExp) {
return host.test(input);
}
};
/**
* Run middleware for named route parameters. Useful for auto-loading or

@@ -745,0 +797,0 @@ * validation.

2

package.json
{
"name": "koa-router",
"description": "Router middleware for koa. Maintained by Forward Email and Lad.",
"version": "11.0.0",
"version": "11.0.1",
"author": "Alex Mingoia <talk@alexmingoia.com>",

@@ -6,0 +6,0 @@ "bugs": {

@@ -28,2 +28,3 @@ # [@koa/router](https://github.com/koajs/router)

* Named routes with URL generation
* Match routes with specific host
* Responds to `OPTIONS` requests with allowed methods

@@ -30,0 +31,0 @@ * Support for `405 Method Not Allowed` and `501 Not Implemented`

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