'how to fetch data with react-app from node,express-server, when react-app is called from server
I have a react-app which is called from my node-server. But the react-app also fetches data from the server. The problem is, that the react-app is just able to fetch data from the server, when this code is deleted:
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, '../build', 'index.html'));
})
Because all requests are going to this app.get('/*'..), even when the react-app trys to fetch images from the server like this:
app.post('/images',express.static('images'));
Because all requests are going to the above function, so its not possible to fetch the images anymore. Thanks for your help.
Solution 1:[1]
You should use
app.use(express.static('images'))
Instead of adding a route. Then you need to add static as prefix to the http path. You could do the same with your react files.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matthias Wiedemann |
