I have trouble getting files from the correct folders when using a nested route in Node JS.
In a standard route like:
router.get('/something', (req, res) => {
res.render('something.html')
})
This <img src="img/image-123.jpg">
inside something.html
works.
However, it doesn't work in createProduct.html
using this route:
router.get('/admin/createProduct', (req, res) => {
res.render('createProduct.html')
})
because the browser tries to look for admin/img/image-123.jpg
which doesn't exist.
I have both routes in an index.js
file using app.use(require('./routes/index'))
And these are the static folders:
app.use(express.static(path.join(__dirname, '/public')));
app.use(express.static(path.join(__dirname, '/uploads')));
app.use(express.static(path.join(__dirname, 'scripts')));
This is my file structure:
How can I prevent this behavior?