mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 08:41:31 +00:00
25 lines
596 B
JavaScript
25 lines
596 B
JavaScript
//replace all the images with local one
|
|
var fs = require("fs");
|
|
|
|
var LOCAL_IMAGE = "/Users/path/to/image.png";
|
|
|
|
module.exports = {
|
|
|
|
//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;
|
|
}
|
|
},
|
|
|
|
dealLocalResponse : function(req,reqBody,callback){
|
|
if(req.replaceLocalFile){
|
|
callback(200, {"content-type":"image/png"}, fs.readFileSync(LOCAL_IMAGE) );
|
|
}
|
|
}
|
|
};
|
|
|