Reputation: 675
I've got a weird issue which I can't seem to figure out with expressjs. I've specified a public
folder for all static files such as js, css and images. I'm using app.use(express.static(__dirname + '/public'));
to specify the folder. This works perfectly except for one case.
Inside the public folder, I've got 3 folders called js
, css
and images
. Within one of my css files, I'm doing background-image: url(/images/bg.png) no-repeat;
but this url is not resolving and the image is not showing on the page.
However, if I do something like img(src='/images/bg.png')
from within one of my views, the image shows. I'm assuming that this has to do with the fact that I'm linking from a static file and node/express are ignoring all routes(?) from within the static files.
How would one go about linking to images in css files located inside a static folder in express?
Upvotes: 4
Views: 2640
Reputation: 2922
Your CSS urls are relitive to the STYLESHEET so the url you have is looking for the path /css/images/bg.png
you want to have the url be ../images/bg.png
Upvotes: 1