【发布时间】:2013-07-31 17:38:28
【问题描述】:
img 的 src 值是否可以重定向到另一个页面?
看来,我有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 吗?
谢谢
【问题讨论】:
标签: html node.js redirect express