admin管理员组文章数量:1221399
I'm running a node.js server on heroku using the express.js framework.
Here is what my server looks like:
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/static'));
var port = process.env.PORT || 8000;
app.listen(port);
My index.html file has the following javascript links:
<script src="/js/chartview.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/bootstrap-select.js"></script>
My directory system looks like this:
server.js
/static
-index.html
-/js
-bootstrap.js
-bootstrap-select.js
-chartview.js
-/css
-bootstrap.css
-bootstrap-select.css
-styles.css
Chrome displays my html page with the appropriate css styles but the console says:
Failed to load resource: the server responded with a status of 404 (Not Found) .js
Failed to load resource: the server responded with a status of 404 (Not Found) .js
Failed to load resource: the server responded with a status of 404 (Not Found) .js
It loads properly when I change my index.html tags to look like this:
<script src="chartview.js"></script>
<script src="bootstrap.js"></script>
<script src="bootstrap-select.js"></script>
And I change my directory systems to look like this:
server.js
/static
-index.html
-bootstrap.js
-bootstrap-select.js
-chartview.js
-/css
-bootstrap.css
-bootstrap-select.css
-styles.css
This is not Ideal, as I would like to have a /js folder.
Any suggestions will be greatly appreciated!
I'm running a node.js server on heroku using the express.js framework.
Here is what my server looks like:
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/static'));
var port = process.env.PORT || 8000;
app.listen(port);
My index.html file has the following javascript links:
<script src="/js/chartview.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/bootstrap-select.js"></script>
My directory system looks like this:
server.js
/static
-index.html
-/js
-bootstrap.js
-bootstrap-select.js
-chartview.js
-/css
-bootstrap.css
-bootstrap-select.css
-styles.css
Chrome displays my html page with the appropriate css styles but the console says:
Failed to load resource: the server responded with a status of 404 (Not Found) https://websitename.herokuapp.com/js/chartview.js
Failed to load resource: the server responded with a status of 404 (Not Found) https://websitename.herokuapp.com/js/bootstrap.js
Failed to load resource: the server responded with a status of 404 (Not Found) https://websitename.herokuapp.com/js/bootstrap-select.js
It loads properly when I change my index.html tags to look like this:
<script src="chartview.js"></script>
<script src="bootstrap.js"></script>
<script src="bootstrap-select.js"></script>
And I change my directory systems to look like this:
server.js
/static
-index.html
-bootstrap.js
-bootstrap-select.js
-chartview.js
-/css
-bootstrap.css
-bootstrap-select.css
-styles.css
This is not Ideal, as I would like to have a /js folder.
Any suggestions will be greatly appreciated!
Share Improve this question edited Dec 13, 2014 at 4:29 atasca10 asked Dec 12, 2014 at 2:19 atasca10atasca10 371 gold badge1 silver badge8 bronze badges 4 |3 Answers
Reset to default 12From the console error, https://websitename.herokuapp.com/js/chartview.js
, the file is not being checked in static folder.
So, change your index.html to include scripts like this.
<script src="js/chartview.js"></script>
i.e remove /
from beginning. as path is relative to index.html.
Follow same process for other three files.
Also, you mentioned that the CSS files are loaded correctly. Can you show how exactly are you including those css files? i.e the path for css.
Comment here, if that doesn't help.
Try Placing your files in the public folder and use the path like this""
Don't use "__dirname" Only using
app.use(express.static('static'));
本文标签:
版权声明:本文标题:javascript - Failed to load resource: the server responded with a status of 404 (Not Found) https:websitename.herokuapp.comjsboo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739255258a2155102.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
https://websitename.herokuapp.com/chartview.js
etc . . . – generalhenry Commented Dec 12, 2014 at 2:21