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
method
It could be a string or an array of strings. If the request method match the middleware would not run.
path
It could is a string, a regexp or an array of any of those. If the request path match, the middleware would not run.
ext
It could be a string or an array of strings. If the request path ends with one of these extensions the middleware would not run.
custom
It 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
useOriginalUrl
It 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