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 ...
随机推荐
- HDU-1994-利息计算
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1994 水题 题目分析 就是两种储存方式,输出所得本金加利息 代码 #include<stdio. ...
- Paxos 实现日志复制同步(Multi-Paxos)
Paxos 实现日志复制同步 这篇文章以一种易于理解的方式来解释 Multi-Paxos 的机制. Multi-Paxos 的是为了创建日志复制 一种实现方式是用一组基础 Paxos 实例,每条记录都 ...
- 本地ssh连接到vbox中的linux
本机是window xp系统, 安装vbox,在vbox下安装linux,想在xp中用ssh连接linux,此时需要配置网络. 1.设置vbox的网络,选择host-only 2.设置window虚拟 ...
- Spring之循环依赖
转:http://my.oschina.net/tryUcatchUfinallyU/blog/287936 概述 如何检测循环依赖 循环依赖如何解决 Spring如何解决循环依赖 主要的几个缓存 主 ...
- 条形码--JsBarcode
介绍一下在GitHub生成条形码的js插件→JsBarcode 支持的条形码: 条码支持的有: CODE128 CODE128 (自动模式切换) CODE128 A/B/C (强制模式)EAN ...
- 解决使用Idea/Eclipse编写Hadoop程序包依赖问题
解决使用Idea/Eclipse编写Hadoop程序包依赖问题 解决包依赖的一种简单粗暴方法就是, 把下载下来的Hadoop压缩包解压, 搜索里面所有的额jar包文件,然后复制到一个目录,在使用Ide ...
- SQLite:自学笔记(1)——快速入门
SQLite的安装和入门 了解 啥是SQLite? SQLite是一种轻巧迷你的关系型数据库管理系统.它的特点如下: 不需要一个单独的服务器进程或操作的系统(无服务器的). SQLite 不需要配置, ...
- ArcGIS制图表达Representation实战篇4-自由式制图表达
ArcGIS制图表达Representation实战篇4-自由式制图表达 by 李远祥 上一章节关于制图表达的控制点中已经介绍过制图表达的编辑功能,利用制图表达的编辑功能,可以实现一些规则以外的效果. ...
- webqq的注册登记和聊天页面--运用jsonp跨域
简介: 我们知道,ajax用于数据交互,但它不能跨域,跨域是指从一个域名的网页去请求另一个域名的资源.比如从http://www.baidu.com/ 页面去请求 http://www.google. ...
- 反汇编看c++引用
继续反汇编系列,本次使用vc2008在x86体系下分析c++中的引用. 定义一个引用类型和将一个变量转换成引用类型一样吗? 引用比指针安全,真的是这样吗,对引用不理解的话比指针还危险. 为什么要用常量 ...