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);
}));

官网:http://js.koahub.com

KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub-skip的更多相关文章

  1. KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub

    Installation $ npm install koahub Use with koa   var app = require('koa')();   var router = require( ...

  2. KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架

    koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...

  3. 基于 Koa.js 平台的 Node.js web 快速开发框架KoaHub.js demo 可安装

    KoaHub.js demo KoaHub.js KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Fu ...

  4. KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub-yilianyun

    koahub-yilianyun 微信易联云打印机接口 koahub-yilianyun易联云打印机node接口 Installation $ npm install koahub-yilianyun ...

  5. io.js - 兼容 NPM 平台的 Node.js 新分支

    io.js(JavaScript I/O)是兼容 NPM 平台的 Node.js 新分支,由 Node.js 的核心开发者在 Node.js 的基础上,引入更多的 ES6 特性,它的目的是提供更快的和 ...

  6. nw.js桌面程序自动更新(node.js表白记)

    Hello Google Node.js 一个基于Google V8 的JavaScript引擎. 一个伟大的端至端语言,或许我对你的热爱源自于web这门极富情感的技术吧! 注: 光阴似水,人生若梦, ...

  7. Node.js 学习笔记(一)--------- Node.js的认识和Linux部署

    Node.js 一.Node.js 简介  简单的说 Node.js 就是运行在服务端的可以解析并运行 JavaScript 脚本的软件. Node.js 是一个基于Chrome JavaScript ...

  8. [Node.js] 00 - Where do we put Node.js

    Ref: 前后端分离的思考与实践(五篇软文) 其实就是在吹淘宝自己的Midway-ModelProxy架构. 第一篇 起因 为了提升开发效率,前后端分离的需求越来越被重视, 同一份数据接口,我们可以定 ...

  9. 基于 Markdown 的开源的 Node.js 知识库平台

    Raneto 是一个免费,开源的 Node.js 知识库平台,基于静态 Markdown 文件实现. Raneto 可以被称为静态网站生成器,因为它并不需要数据库支持.所有的内容都存储在 Markdo ...

随机推荐

  1. HTML5 Canvas、内联 SVG、Canvas vs. SVG

    canvas 元素用于在网页上绘制图形. 什么是 Canvas? HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像. 画布是一个矩形区域,您可以控制其每一像素. canv ...

  2. lufylegend库 LButton

    lufylegend库 LButton <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  3. {}typeof string转为 obj json

    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.3/jquer ...

  4. tomcat服务器搭建之ngrok——将内网地址映射到外网

    最近心血来潮,想学习微信公众号开发.但是自己又没有外网服务器,这个给我带来很大的麻烦. 刚开始申请了新浪云服务和百度云服务,将写好的代码打包丢到相应的云服务器上就行. 但问题就来了,开发中避免不了错误 ...

  5. jquery.validate.js之自定义表单验证规则

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  6. java算法 蓝桥杯 乘法运算

    问题描述 编制一个乘法运算的程序. 从键盘读入2个100以内的正整数,进行乘法运算并以竖式输出. 输入格式 输入只有一行,是两个用空格隔开的数字,均在1~99之间(含1和99). 输出格式 输出为4行 ...

  7. System.Web.Caching.Cache 方法汇总

    在做后台的时候,想着把所有栏目放到缓存里,就这里了一个类.必然是有缺陷,暂时没有实现滑动缓存 using System; using System.Collections; using System. ...

  8. 最快让你上手ReactiveCocoa之基础篇(简称RAC)

    前言 很多blog都说ReactiveCocoa好用,然后各种秀自己如何灵活运用ReactiveCocoa,但是感觉真正缺少的是一篇如何学习ReactiveCocoa的文章,小编看了很多篇都没看出怎么 ...

  9. pwnable.kr-fd-Writeup

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  10. Spring装配Bean---使用xml配置

    声明Bean Spring配置文件的根元素是<beans>. 在<beans>元素内,你可以放所有的Spring配置信息,包括<bean>元素的声明. 除了Bean ...