admin管理员组文章数量:1332881
I'm using Express and for some reason, when using JavaScript I can access images but whenever I try and directly implement the image route to the src such as
<img src="images/background.png">
The localhost determines that it is unable to get the image.
I'm pointing a static to a /public
route in the server.js
file which is why it is baffling me as to why it can receive some images but not all?
This is my current line that determines the public route.
app.use(express.static('public'));
I'm using Express and for some reason, when using JavaScript I can access images but whenever I try and directly implement the image route to the src such as
<img src="images/background.png">
The localhost determines that it is unable to get the image.
I'm pointing a static to a /public
route in the server.js
file which is why it is baffling me as to why it can receive some images but not all?
This is my current line that determines the public route.
app.use(express.static('public'));
Share
Improve this question
edited Mar 15, 2017 at 21:46
lin
18.4k4 gold badges65 silver badges87 bronze badges
asked Mar 15, 2017 at 21:34
cmiotkcmiotk
3152 gold badges3 silver badges10 bronze badges
0
2 Answers
Reset to default 6Try a absolute path definition:
var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
Your directroy structure should look like this:
server.js -> "where app.use(express.static()) is defined"
---| public
-------| images
-----------| background.png
I couldnt GET my png because there were some invisible characters in the name of the file. Make sure there are no special characters in the file name, you can try renaming it.
本文标签: javascriptExpress Cannot GET imagesStack Overflow
版权声明:本文标题:javascript - Express Cannot GET images - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742310662a2450802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论