Linking a static file from statics in Expressjs

I have a strange problem that I cannot understand with expressjs. I have specified a public folder for all static files like js, css and images. I am using app.use(express.static(__dirname + '/public')); to specify a folder. This works great, except in one case.

In the shared folder, I have 3 folders named js , css and images . In one of my css files, I am doing background-image: url(/images/bg.png) no-repeat; , but this URL is not allowed, and the image does not appear on the page.

However, if I do something like img(src='/images/bg.png') from one of my views, the image shows. I assume this is due to the fact that I am linking to a static file, and node / express ignore all routes (?) From static files.

How can I link image links in css files located inside a static folder in an expression?

+4
source share
1 answer

Your CSS URLs are relevant to STYLESHEET, so the URL you have is looking for the path /css/images/bg.png , which should have the URL ../images/bg.png

+1
source

Source: https://habr.com/ru/post/1347633/


All Articles