I have the following folder structure:
/app
server.js
/public
1.jpg
I want to be able to access the 1.jpg image from the URI /1.jpg
.
In my server.js
file, I added the following middleware at the top:
app.use('/', express.static('../public'));
and in the buttom i have a middleware that catch not found routes:
app.all('*', (req, res) => {
res.status(404).json({
success: false,
message: `Can't find ${req.originalUrl} on this server!`
});
});
When i make a request to: /1.jpg i got the following response:
{
"success": false,
"message": "Can't find /1.jpg on this server!"
}
Even if it should serve the first middleware which is the image