Connect中间件——可配置的中间组件
2016-03-13 21:21
387 查看
logger.js
var connect = require('connect'); var app = connect() .use(setup(':method :url')) .use(hello) .listen(3000); function hello(req, res) { res.setHeader('Content-Type', 'text/plain'); res.end('hello world'); } /* 可配置的Connect中间件组件 */ function setup(format) { var regexp = /:(\w+)/g; return function logger(req, res, next) { // 用正则表达式格式化请求的日志条目 var str = format.replace(regexp, function(match, property) { return req[property]; }); console.log(str); next(); } }
相关文章推荐
- 简述extern的作用,说明什么时候会使用extern?
- oclhashcat配合pwdump破解win7密码
- 深入理解line-height与vertical-align
- 第三周仿真作业
- 自定义Dialog中加EditText弹不出键盘跟Dialog遮挡键盘的问题
- CodeForces 630Q:Pyramids【几何】
- 分别写出BOOL,int,float,指针类型的 变量a与零相比的语句
- 【机房重构】视图
- 自定义主题
- android studio 开发环境搭建及常见问题解决方法
- 区域生长算法原理及MATLAB实现
- 还是决定在这里留下自己的足迹
- iOS开发UI篇—核心动画(关键帧动画)
- 使用病毒库检查手机中已经安装的程序
- JMS实例
- <!DOCTYPE>标签的定义与用法
- 算法训练 最大的算式
- Connect中间件示例
- 测试思考
- 判断是否为平衡二叉树--递归法