【发布时间】:2016-06-21 18:33:26
【问题描述】:
我正在尝试在 Heroku 上显示一个带有图像标签的 html 页面。该图像存在,但我无法弄清楚要使用什么路径才能找到它。我尝试的每个绝对路径都会出现 404 错误,并且我不能使用相对路径,因为它会将其附加到加载 html 页面的位置(恰好是 /api/errorcodes/x,其中 x 是用于查找原始 html 页面的编号)IE
app.get('/api/errorcode/:errorcode', function(request, response) {
var errorcode = request.params.errorcode;
var doc = 'Error' + errorcode + '.html';
console.log('__dirname = ', __dirname);
response.sendFile(__dirname + '/views/pages/' + doc);
});
所以目录结构如下:
views/pages/Error1.html
视图/页面/Error1.fld/img001.png
Error1.html 有 <img src="/views/pages/Error1.fld/img001.png"> 并返回 404(页面 Error1.html 加载,但图像在 heroku 日志中得到 404)。
我也尝试过“/app/views/pages/Error1.fld/img001.png”以及将图像移动到 /public 并从那里尝试相同的组合。我如何告诉 img 标签在哪里可以找到图像?!
【问题讨论】: