How do I run a React app locally using npm serve

54 views Asked by At

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?

0

There are 0 answers