KoaHub平台基于Node.js开发的Koa的skip插件代码详情
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 = 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
methodit could be an string or an array of strings. If the request method match the middleware will not run.pathit could be an string, a regexp or an array of any of those. If the request path match, the middleware will not run.extit could be an string or an array of strings. If the request path ends with one of these extensions the middleware will not run.customit must be a function that returnstrue/false. If the function returns true for the given request, ithe middleware will not run. The function will have access to Koa's context viathisuseOriginalUrlit should betrueorfalse, default istrue. if false,pathwill match againstctx.urlinstead ofctx.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);
}));
wemall地址:http://www.wemallshop.com
代码地址:http://js.koahub.com/home/feature/koahub-skip

KoaHub平台基于Node.js开发的Koa的skip插件代码详情的更多相关文章
- KoaHub平台基于Node.js开发的Koa 连接支付宝插件代码信息详情
KoaHub平台基于Node.js开发的Koa 链接支付宝插件代码信息详情 easy-alipay alipay payment & notification APIs easy-alipay ...
- KoaHub平台基于Node.js开发的Koa JWT认证插件代码信息详情
koa-jwt Koa JWT authentication middleware. koa-jwt Koa middleware that validates JSON Web Tokens and ...
- KoaHub平台基于Node.js开发的Koa router路由插件代码信息详情
koa-router Router middleware for koa. Provides RESTful resource routing. koa-router Router mid ...
- KoaHub平台基于Node.js开发的Koa EJS渲染插件代码信息详情
koa-ejs ejs render middleware for koa koa-ejs Koa ejs view render middleware. support all feature of ...
- KoaHub平台基于Node.js开发的Koa的简单包装到请求库的类似接口
co-request co-request promisify wrapper for request co-request Simple wrapper to the request library ...
- KoaHub平台基于Node.js开发的Koa的调试实用程序
debug small debugging utility debug tiny node.js debugging utility modelled after node core's debugg ...
- KoaHub平台基于Node.js开发的Koa的连接MongoDB插件代码详情
koa-mongo MongoDB middleware for koa, support connection pool. koa-mongo koa-mongo is a mongodb midd ...
- KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情
koa-static-server Static file serving middleware for koa with directory, rewrite and index support k ...
- KoaHub平台基于Node.js开发的Koa的get/set session插件代码详情
koa-session2 Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb ...
随机推荐
- easyui-datagrid分页查询
不想写语言描述了,直接代码吧! js: $(document).ready(function () { var driver_datagrid; $('#job').combobox({ url: ' ...
- Java线程:堵塞队列与堵塞栈
一.堵塞队列 Java定义了堵塞队列的接口java.util.concurrent.BlockingQueue,堵塞队列是一个指定长度的队列,当试图向队列中添加元素而队列已满,或者是想从队列移出元素而 ...
- jQuery基本过滤选择器
jQuery基本过滤选择器: <h1>this is h1</h1> <div id="p1"> <h2>this is h2< ...
- C# 枚举的使用
/// <summary> /// 枚举的使用 /// 主要功能:使用枚举的值DataTypeId.Money,获取对应的Money字符串. /// </summa ...
- 给Pomelo的聊天室添加time的RPC调用
为了练手,给聊天应用增加一个rpc调用和一个time类型的服务器,在servers/time/remote/timeRemote.js中,添加如下代码: module.exports.getCurre ...
- LinuxMint18配置Grub2默认启动操作系统
---恢复内容开始--- 之前电脑里面装了太多系统太乱了,刚好假期回家有一些空闲时间于是开始了重装计划. 现在重新弄好了,有两个系统,一个是Windows10,另一个是LinuxMint18,但是我平 ...
- mac命令行对复杂ipa包重新签名
最近在做ios的自动化平台,需要通过命令行安装卸载ipa包 好了问题来,别人上传的ipa包,很可能是开发签名了只能在特定手机上安装的测试ipa包,那我们如何将其安装在我们的自动化的iphone上呢? ...
- Docker - 用Flannel跨主机
试了下比较流行的几种SDN,感觉flannel还是比较好用,这里简单记录一下. 用的是virtualbox,3个机器,分别为: genesis : inet 192.168.99.103/24 brd ...
- Word常用实用知识1
Word常用实用知识1 纯手打,可能有错别字,使用的版本是office Word 2013 转载请注明出处,谢谢. 快速输入日期(含格式) [插入]--[日期] 快速输入日期和时间(快捷键) 快速 ...
- [html5] 学习笔记-Canvas应用
通过使用HTML5游戏开发的引擎CreatJS,创建HTML5 Canvas上的更好交互. 1.认识CreateJS CreateJS是一个外部库,用它可以比Canvas更方便的绘制图形. 官网:ht ...