2014-09-01 16:38:43 +08:00
|
|
|
//replace all the images with local one
|
2014-10-21 13:46:32 +08:00
|
|
|
var fs = require("fs");
|
2014-09-01 16:38:43 +08:00
|
|
|
|
2014-10-21 13:44:22 +08:00
|
|
|
var LOCAL_IMAGE = "/Users/path/to/image.png";
|
2014-09-01 16:38:43 +08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
2014-10-21 14:49:13 +08:00
|
|
|
summary:function(){
|
|
|
|
return "replace all the images with local one";
|
|
|
|
},
|
|
|
|
|
2014-10-21 13:44:22 +08:00
|
|
|
//mark if use local response
|
|
|
|
shouldUseLocalResponse : function(req,reqBody){
|
|
|
|
if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
|
|
|
|
req.replaceLocalFile = true;
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
2014-09-01 16:38:43 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-09-02 14:54:45 +08:00
|
|
|
dealLocalResponse : function(req,reqBody,callback){
|
2014-09-01 16:38:43 +08:00
|
|
|
if(req.replaceLocalFile){
|
2014-10-21 13:44:22 +08:00
|
|
|
callback(200, {"content-type":"image/png"}, fs.readFileSync(LOCAL_IMAGE) );
|
2014-09-01 16:38:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|