I have a React app and I want to serve a production build using the below script:
"serve": "serve -s build"
While the application loads with the above command, I cannot get the API calls to work. For example the calls to http://localhost:3000/api/users return the index.html instead of the JSON response.
Actually for the API calls, I have a craco.config.js as below:
devServer: {
static: 'src',
hot: true,
port: 3000,
historyApiFallback: {
disableDotRule: true
},
proxy: {
'/api/**': {
target: {
port: 8080
},
secure: false
}
},
},
With serve, how do I get these API calls to work? Is it somehow possible to have the APIs running on port 8080 and those work when running locally using npm run serve?