In ExpressJS, virtual path prefix helped me resolve accessing static assets from public folder in a multi-level path site. Here, i am trying to access from Favicon which is in public\images\favicon.ico
and in my HEAD tag pug file has something like this and this pug file is used in rendering all the pages.
link(rel="shortcut icon" href="../images/favicon.ico")
This works in,
- http://localhost:3000/ - Works
- http://localhost:3000/category/world - Works
- http://localhost:3000/category/world/article - Doesn’t work
Added the below highlighted line to resolve the above issue. So as per the doc
To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
Note : However, the path that you provide to the express.static function is relative to the directory from where you launch your node process.