http://localhost:8080/path/style.css not found
- I had a problem with the routes I was calling from my index.html and the static routes that were handled by node.
This were the links to my
style.css
and mybundle.js
:
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="public/style/style.css">
</head>
<body>
<div id="root"></div>
<script type="application/javascript" src="bundle.js"></script>
</body>
The problem with this routes was that they were not absolute but related to the path that preceeded them. This was the right way to do it:
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/public/style/style.css">
</head>
<body>
<div id="root"></div>
<script type="application/javascript" src="/bundle.js"></script>
</body>
- In regards to Node/express I had to set a route to the statics that would find both files, like this:
server.use('/', express.static(__dirname + '/dist'));
The first /
adds a fake path before every static route. For instance: if instead of /
I wrote /statics
then all of my
files from dist would now have an /statics
right before the file path, like this: http://localhost:8080/statics/style.css
when actually there is no such /statics
folder containing the files.
The /dist
added latter to the express.static
method sets the route where express has to look for the static files.