Comparing version 1.0.10 to 1.0.11
{ | ||
"name": "hrt", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "HTTP Rewrite Tool", | ||
@@ -5,0 +5,0 @@ "author": "Longhao Luo <lhluo@tudou.com>", |
@@ -9,3 +9,3 @@ var Path = require('path'); | ||
function stripVersionInfo(url) { | ||
return url.replace(/([^?]+)_\d+(\.(?:js|css|swf))/i, '$1$2'); | ||
return url.replace(/([^?]+)_\d+(\.(?:js|css|swf|png|jpg|gif))/i, '$1$2'); | ||
} | ||
@@ -12,0 +12,0 @@ |
@@ -8,12 +8,6 @@ HTTP Rewrite Tool | ||
1. 源代码安装 | ||
``` | ||
git clone git://github.com/tudouui/hrt.git | ||
``` | ||
``` | ||
npm install hrt -g | ||
``` | ||
2. NPM安装 | ||
``` | ||
npm install hrt -g | ||
``` | ||
### 使用方法 | ||
@@ -71,2 +65,18 @@ | ||
``` | ||
注:当配置文件里有 `exports.merge` 时会接管所有请求,所以在程序逻辑里需要加入文件类型判断。 | ||
注:当配置文件里有 `exports.merge` 时会接管所有请求,所以在程序逻辑里需要加入文件类型判断。 | ||
3. 修改URL内容。 | ||
```js | ||
exports.merge = function(path, callback) { | ||
if (/^http:\/\/(www|wwwtest|beta)\.tudou\.com\/programs\/view\//.test(this.req.url)) { | ||
this.util.get(this.req.url, 'gbk', function(body) { | ||
callback('text/html', body + '<!-- test -->', 'gbk'); | ||
}); | ||
return; | ||
} | ||
// 其它请求 | ||
var contentType = require('mime').lookup(path); | ||
var buffer = this.util.readFileSync(path); | ||
return callback(contentType, buffer); | ||
}; | ||
``` |
1158389
80