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

  • 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 Koa's 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);
}));

  

wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统

wemall地址:http://www.wemallshop.com
代码地址:http://js.koahub.com/home/feature/koahub-skip

KoaHub平台基于Node.js开发的Koa的skip插件代码详情的更多相关文章

  1. KoaHub平台基于Node.js开发的Koa 连接支付宝插件代码信息详情

    KoaHub平台基于Node.js开发的Koa 链接支付宝插件代码信息详情 easy-alipay alipay payment & notification APIs easy-alipay ...

  2. KoaHub平台基于Node.js开发的Koa JWT认证插件代码信息详情

    koa-jwt Koa JWT authentication middleware. koa-jwt Koa middleware that validates JSON Web Tokens and ...

  3. KoaHub平台基于Node.js开发的Koa router路由插件代码信息详情

    koa-router Router middleware for koa. Provides RESTful resource routing. koa-router       Router mid ...

  4. KoaHub平台基于Node.js开发的Koa EJS渲染插件代码信息详情

    koa-ejs ejs render middleware for koa koa-ejs Koa ejs view render middleware. support all feature of ...

  5. KoaHub平台基于Node.js开发的Koa的简单包装到请求库的类似接口

    co-request co-request promisify wrapper for request co-request Simple wrapper to the request library ...

  6. KoaHub平台基于Node.js开发的Koa的调试实用程序

    debug small debugging utility debug tiny node.js debugging utility modelled after node core's debugg ...

  7. KoaHub平台基于Node.js开发的Koa的连接MongoDB插件代码详情

    koa-mongo MongoDB middleware for koa, support connection pool. koa-mongo koa-mongo is a mongodb midd ...

  8. KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情

    koa-static-server Static file serving middleware for koa with directory, rewrite and index support k ...

  9. 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 ...

随机推荐

  1. redhat6.4下安装Oracle11g

    一.在Root用户下执行以下步骤: 1)修改用户的SHELL的限制,修改/etc/security/limits.conf文件 *               soft    nproc  2047 ...

  2. EF 4.1 学习资源汇总

    微软发布了EF 4.1以后,结合asp.net mvc3,网站的开发可谓是非常方便.但是作为一种新技术,如何开始你的学习之路呢? 首先是关于 EF 4.1的安装和介绍,以及nuget的使用. http ...

  3. jQuery获取URL中所带参数的办法

    可以使用正则表达式进行结果的拆分: http://www.cnblogs.com/babycool/p/3169058.html 可以直接进行所需内容的split: http://blog.scien ...

  4. cocos2dx内存管理的个人理解

    1.一帧开始之后的过程中,将所有执行到的autorelease的对象加入到池中:2.一帧结束之前取出池中的所有对象记作objs,清空池:3.对取出来的objs进行遍历,每个元素进行一次release: ...

  5. 从Chrome源码看浏览器的事件机制

    .aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto } .crayon-line spa ...

  6. TimSort算法分析

    Timsort是一种混合稳定的排序算法,采用归并排序混合插入排序的设计,在多种真实数据上表现良好. 它基于一个简单的事实,实际中大部分数据都是部分有序(升序或降序)的. 它于2002年由Tim Pet ...

  7. tomcat的配置

    配置tomcat需要 先下载JDK JDE配置环境http://jingyan.baidu.com/article/870c6fc33e62bcb03fe4be90.htmlXML配置 路径——> ...

  8. 简单了解Hibernate

    orm 对象 object 关系relational映射 mppingorm对象关系映射hibernate 框架是什么?很简单 持久化框架  他轻松的封装了jdbc那些繁琐的操作什么是持久化?持久化就 ...

  9. 内存管理 (C++)

    转:http://hi.baidu.com/%D0%A1%B0%FC%D7%D349/blog/item/de1a8e4fa5eeafc3d0c86a68.html1.进程地址空间    Window ...

  10. C#基础笔记1

    1>>数据类型: Int double:小数 char:字符型,只能存储一个字符,并且存储的这个字符要用单引号引起来.如:'a'; string:字符串,可以储存多个字符,用双引号引起来( ...