0
votes

I am trying to setup react and spring boot in development mode.I have running front end and back end separate ports i.e; http://localhost:3000/api/hello and http://localhost:8080/api/hello respectively. I like to call services in the backend and display the results in the frontend, for that i have add "proxy": "http://localhost:8080" in react app package.json file. But its not working.

Plz help me how to fix?

package.json file

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:8080",
}

I am enable to display back end spring boot code with front end reactjs code

1

1 Answers

0
votes

You don't have to define proxy port. Simply run your spring boot project and then send request from react application

For example in React:

        fetch("http://localhost:portNumber/login", {
        method: 'POST',
        headers: {'content-type': 'application/json'},
        body: JSON.stringify({
        email: this.state.emailAddress,
        password: this.state.password})
})
        .then(resopnse => {
    if(response.status === 200){
    }
        })

Spring boot:

@CrossOrigin("*")
@PostMapping("/login")
public userLogin(@RequestedBody modalName objectname){
//Service Call
}