Koahub.js--Koahub-skip of node. JS Web Rapid development framework based on Koa.js platform

Source: Internet
Author: User

Koahub-skip

Koahub Skip Middleware

Koahub Skip

Conditionally skip a middleware when a condition is met.

Install
npm i koahub-skip --save
Usage

With existing middlewares:

var skip  = require Koahub-skip ' ) ; var serve = require(' koa-static');  var static < span class= "keyword operator assignment js" >= serve __dirname +  /public ' ) static. Skip = Skip;  App. Use ( Static. Skip ( { method:  ' options"  }) " ;

If You is authoring a middleware you can support skip as follow:

module. Exports = function () { var mymid = function *(next) { //do something   };  mymid. Skip = require(' Koahub-skip');   return mymid; };Current options
  • methodIt could be a string or an array of strings. If the request method match the middleware would not run.
  • pathIt could is a string, a regexp or an array of any of those. If the request path match, the middleware would not run.
  • extIt could be a string or an array of strings. If the request path ends with one of these extensions the middleware would not run.
  • customIt must is a function that returns true / false . If The function returns true for the given request, ithe middleware would not run. The function'll has access to Koa ' s context viathis
  • useOriginalUrlIt should are true or false , default is true . If False, would path match against ctx.url instead of ctx.originalUrl .
Examples

Require authentication for every request skip the path is index.html.

App.Use(Requiresauth(). Skip ( { path: [/index.html ' ,  / ' ]  }) )

Avoid a fstat for request to routes doesnt end with a given extension.

app. Use(static. Skip(function () { var ext=urlparse (this. Originalurl) .pathname.substr-4" Return!~['. jpg‘, Html , " css ' , ". Js ]. (ext" ; }));

Official website: http://js.koahub.com

Koahub.js--Koahub-skip of node. JS Web Rapid development framework based on Koa.js platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.