1
img
可以將src值重定向到另一個頁面嗎?ExpressJS/NodeJS重定向圖像
考慮,我有img
:
<img src='/images/fileName'/>
在app.js
app.get('/images/:fileName', subject.image);
這是我的路線:
exports.image = function(req, res){
var fileName = req.fileName;
fs.exists(fileName, function(exists){
if (exists) {
res.sendfile(imagePath);
}else{
res.redirect('http://gravatar.com/avatar/_some_hash');
}
});
}
我的代碼工作,但它是沒關係如果圖片不存在,請使用res.redirect
?
謝謝