I want to serve my react front-end on localhost:5000, and the api requests will go to localhost:5000/api/some-path.
I have seen some similar questions and from what I have understood :
Add proxy in package.json
Serve static files from build folder
relevant part of package.json:
"proxy" : "http://localhost:5000",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Relevant part of server.js :
const PORT = 5000 || process.env.port;
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function(req,res) {
res.sendFile(path.join(__dirname, '../public', 'index.html'));
});
Commands for production :
$ npm run build
$ serve -s build
The issue is that, each fetch request's response is the index.html file.
Note that, in the dev build everything was working fine. I was starting react app from port 3000 and requests were going to localhost:5000/api/path responding with json data.