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

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

时间: 2024-07-29 15:16:21

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

基于 Koa平台Node.js开发的KoaHub.js的控制器,模型,帮助方法自动加载

koahub-loader koahub-loader是基于 Koa平台Node.js开发的KoaHub.js的koahub-loader控制器,模型,帮助方法自动加载 koahub loader Installation $ npm install koahub-loader Use with koa // 1.model loader var model = loader([ {      root: './app/model',      suffix: '.model.js' }, { 

基于 Koa平台Node.js开发的KoaHub.js连接打印机的代码

最近好多小伙伴都在做微信商城的项目,那就给大家分享一个基于 Koa.js 平台的 Node.js web 开发的框架连接微信易联云打印机接口的代码,供大家学习.koahub-yilianyun 微信易联云打印机接口 koahub-yilianyun易联云打印机node接口 Installation $ npm install koahub-yilianyunUse with co-request var printer = require('koahub-yilianyun');var resu

基于 Koa平台Node.js开发的KoaHub.js获取/设置会话功能代码

koa-session2 Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb with Babel koa-session2     Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb with Babel If you are not using bab

基于 Koa平台Node.js开发的KoaHub.js的静态服务器重写和索引代码

koa-static-server Static file serving middleware for koa with directory, rewrite and index support koa-static-server static file serving middleware for koa with directory, rewrite and index support Installation $ npm install koa-static-server API var

基于 Koa平台Node.js开发的KoaHub.js的模板引擎代码

koahub-handlebars koahub-handlebars koahub handlebars templates Installation $ npm install koahub-handlebars Use with koa var koa = require('koa'); var hbs = require('koahub-handlebars'); var app = koa(); // koahub-handlebars is middleware. `use` it 

基于 Koa平台Node.js开发的KoaHub.js的输出json到页面代码

koahub-body-res koahub body res Format koa's respond json. Installation $ npm install koahub-body-res Use with koa var app = require('koa')(); var koaRes = require('koahub-body-res'); app.use(koaRes()); this.data = 'This is a body'; this.msg = 'This 

[Tizen开发]基于Tizen平台的终端开发模拟器1 - Web

1.  官方 模拟器 Tutorials https://01.org/web-simulator/ 2. 最新版本发布于 2013.05 I am honored to introduce the Web Simulator for its public release on 01.org. The Web Simulator is a lightweight mobile application development and testing tool for web application

基于LBS平台的iOS开发

LBS,即Location Based Services,基于位置服务,用于定位.导航等功能,比如地图应用.订外卖等的app就需要这个功能. 在这里我使用的是高德LBS开放平台,地址:http://lbs.amap.com/ 进入网站,首先注册并认证为开发者,然后为你的每个APP申请一个key,其中安全码(Bundle Identifier)通过Xcode切换到General标签,查看Bundle Identifier. 使用第三方服务,我们可以使用自动配置,这里就要使用到Cocoapods.C

基于CkEditor实现.net在线开发之路(2)编写C#代码,怎么调用它。

上一章简约的介绍了CkEditor编辑器,可以编辑js逻辑代码,css,html,C#代码,这章我根据实际例子,讲解怎么编写C#代码和怎么调用它. 大家都还记得刚刚接触程序编时的hello Word吧,首先我来介绍在编辑器上写了返回“hello Word”的C#方法,让后怎么去调用返回对应hello Wrod方法,具体代码如下: 运行预览效果如下图 页面加载之后就弹出了hello world对话框.证明获取到了我们写返回字符串. 注意编辑C#代码 并可以用ajax调用,C#代码方法必须要有一定的