React Js does not get images after hosting on netlify

Viewed 17

I am hosting React app on Netlify and NodeJs server on Heroku.

The image is hosted on the server directory, in an "image" folder..

     // Build the image path
        const file = req.file ? 
        req.protocol + '://' + req.get('host') + '/' + req.file.path 
        : null;

The code above is building the image link which will be stored in the database and will be looking like "https://home-renter.heroku.com/images/1663093729973.jpg". Normally, if I paste the link on the browser, the server should send the image... But in this case I get 404 error.... The image link is saved into the mongodb as enter image description here

In the chrome console I have the following errors and warnings: enter image description here

I do not know what should I look for. I dont have a starting point...

Update. If I add a house, and upload images, the image selection works. However if I refresh the page, the website crashes and send 404...

// Static files
const path = require('path')
app.use('/images', express.static(path.join(__dirname, 'images')));


app.get('/', (req, res, next) => res.send('Wellcome to home renter'));

Update

The problem was while I was deleting the images from the post. I was splitting the image link from 3000 (port) instead of the new URL.

0 Answers
Related