0

This is my package.json in react.

{
  "name": "reactjs",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "bootstrap": "^4.5.3",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.0",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"

  },
  "proxy": "http://localhost:8080",
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I used proxy in the package.json file but it doesn't work for me. after adding this proxy it didn't show any error but also host in local host3000.

1 Answers1

0

React is regularly front-end framework. This means at the end of the day, It will be built to bunch of js file. Hence react-scripts build. You should deploy those files to a proper HTTP server that can serve static files. Check this out for making HTTP file server out of node https://stackoverflow.com/a/16350826/3849555 . react-scripts start is just starting web server for development-purpose only. Do not use it as real web server.

Chayne P. S.
  • 1,558
  • 12
  • 17
  • is it necessary to run both backend and frontend in the same localhost when we develop the application? –  Nov 04 '20 at 04:21
  • @JanithaMissaka You can see that the HTTP server that host React frontend app as a app store. The job of the server is to distribute the app to browsers but the app running on browser. Real backend that produce REST API can be on different host but you can proxy it in development env. – Chayne P. S. Nov 04 '20 at 17:09