Different static files path on nested routes

Hi, I'm having trouble with static files:
My problem is:

Then I creating a http-in with route /blog, all static files loading ok http://localhost:1880/images/posts/post-2-70x70.jpg

But if i add another route like /blog/posts, all static files loads http://localhost:1880**/blog/**images/posts/post-2-70x70.jpg

So it adds parent route to the path of static files.
Any ideas why it happens?

node-red - 2.1.3
os: win 8.1
nodejs - 14.18.1

Hello Vaidas,

with routes /blog and /blog/posts you are serving an html page?
how have you configured httpStatic in your settings.js file and
how is the folder structure of the static folder ?
Can you share an example flow to demonstrate the problem ?

if i had to guess .. the html serving images from /blog/posts
should have a src ../images/posts/<imageName>.jpg
.. to go one level out of the url path ?

Hello UnborN,

Yes I'm serving html,
in settings I use it like this > httpStatic: path.join(__dirname,"static");
static folder structure is like this:
www
--static
----images
------avatars
------banners
------etc...
----vendor
----js
----css

Well your example did the trick ../../images/posts/.jpg, I had to go two levels up.

Update:
I did some research and find this
Relative Path Summary (applicable to href, src etc.,):

/file_Or_FolderName          Root directory
./file_Or_FolderName         Current directory
../file_Or_FolderName        Previous directory (One level up)
../../file_Or_FolderName     Previous of previous directory (Two levels up)
../../../file_Or_FolderName  Just like above - Three levels up 

so in my case I use /file_Or_FolderName. It also works fine and don't have to worry about how deep route can go, always will return to root.

Thanks.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.