KoaHub平台基于Node.js开发的Koa的skip插件代码详情
来源:互联网 发布:魏无羡捏脸数据 编辑:程序博客网 时间:2024/04/26 03:49
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 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 viathis
useOriginalUrl
it should betrue
orfalse
, default istrue
. if false,path
will match againstctx.url
instead 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 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
wemall地址:http://www.wemallshop.com
代码地址:http://js.koahub.com/home/feature/koahub-skip
0 0
- KoaHub平台基于Node.js开发的Koa的skip插件代码详情
- KoaHub平台基于Node.js开发的Koa的模板系统handlebars插件代码详情
- KoaHub平台基于Node.js开发的Koa的get/set session插件代码详情
- KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情
- KoaHub平台基于Node.js开发的Koa的连接MongoDB插件代码详情
- KoaHub平台基于Node.js开发的Koa加载程序代码信息详情
- KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架
- KoaHub.JS基于Node.js开发的Koa 生成验证码插件代
- KoaHub平台基于Node.js开发的Koa的简单包装到请求库的类似接口
- KoaHub.JS基于Node.js开发的mysql的node.js驱动程序代码
- KoaHub.JS基于Node.js开发的处理和显示日期代码
- KoaHub.JS基于Node.js开发的Lodash模块化实用程序代码
- node.js的koa框架
- KoaHub.JS用于Node.js的cron作业调度程序代码
- KoaHub.JS用于Node.js的可移植Unix shell命令程序代码
- 【知识整理】Node.js-Koa之Web App的功能
- Node.js-koa入门
- express(基于 Node.js 平台,快速、开放、极简的 web 开发框架)
- Springboot 之 多文件上传-知识林
- tjut 5938
- css3第一天(上)
- SharedPreferenceUtil
- 拉格朗日对偶
- KoaHub平台基于Node.js开发的Koa的skip插件代码详情
- 抓取百度关键词排名、标题、连接、描述
- JDBC直接连接数据库
- 二次型(求梯度) —— 公式的简化
- Stacked Autoencoders学习笔记
- 多重背包(原本是一个01背包)
- 拼图响应式前端框架版响应式后台正式发布
- 使用多态替代If else或switch的更多尝试
- Zookeeper--Zookeeper是什么