How to access backend data in reactjs (via create-react-app's npm start)

161 views Asked by At

So I can get the data if I npm run build my app and run it via it's usual address. But with npm start it doesn't know/(can't reach) the specified location.

So how might I go about doing this so it can work both ends?

package.json

{
  "name": "reactjs",
  "version": "0.1.0",
  "private": true,
  "homepage": "/reactjs/build",
  "devDependencies": {
    "lite-server": "^2.2.2",
    "react-scripts": "0.8.4"
  },  
  "dependencies": {
    "datatables.net": "^1.4.2",
    "datatables.net-dt": "^1.4.2",
    "griddle-react": "^0.7.1",
    "jquery": "^3.1.1",
    "react": "^15.4.1",
    "react-dom": "^15.4.1",
    "react-router": "^3.0.0"
  },  
  "scripts": {
    "start": "react-scripts start eslint-disable",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "dev": "lite-server -c config/bs-config.js"
  }
}
1

There are 1 answers

0
A. L On

Add proxy to it e.g.

"homepage": "/reactjs/build",
"proxy": "http://localhost/supermarkets