失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 基于 Koa平台Node.js开发的KoaHub.js的跳过组件代码

基于 Koa平台Node.js开发的KoaHub.js的跳过组件代码

时间:2021-10-30 05:55:29

相关推荐

基于 Koa平台Node.js开发的KoaHub.js的跳过组件代码

php教程|php手册

thinkphp代码,代码示例,代码参考,php短信,数据库备份代码,令牌验证,去除代码中的空白和注释Koa.js,No

php教程-php手册

oaHub.js的跳过组件代码

koahub-skip

综合网站管理系统源码,ubuntu安装库函数,代码爬虫 秒杀下单,html ,seo企业外包lzw

koahub skip middleware

爱客影视源码系统,vscode全词匹配,ubuntu 屏幕方向,定时重启tomcat项目,sqlite3删除第一条,爬虫 monggodb,php典型模块精解,惠州seo网络哪里好,网站页面加载效果,html扁平化模板lzw

koahub skip

Conditionally skip a middleware when a condition is met.

易语言制作我是猪源码,vscode注解快捷键,ubuntu 读写efi,tomcat启动的类,仓鼠爬虫图片,php xmpp 服务器,信息化seo优化案例,dw网站背景音乐,html5响应式模板使用lzw

Install

npm i koahub-skip –save

Usage

With existing middlewares:

var skip = require(koahub-skip);

var serve = require(koa-static);

var static = serve(__dirname + /public);

static.skip = skip;

app.use(static.skip({ method: OPTIONS }));

If you are 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 an string or an array of strings. If the request method match the middleware will not run.

path it could be an string, a regexp or an array of any of those. If the request path match, the middleware will not run.

ext it could be an string or an array of strings. If the request path ends with one of these extensions the middleware will not run.

custom it must be a function that returns true / false. If the function returns true for the given request, ithe middleware will not run. The function will have access to Koas context via this

useOriginalUrl it should be true or false, default is true. if false, path will 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 = url.parse(this.originalUrl).pathname.substr(-4);

return !~[.jpg, .html, .css, .js].indexOf(ext);

}));

官网:

如果觉得《基于 Koa平台Node.js开发的KoaHub.js的跳过组件代码》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。