W
W
Wasya UK2019-08-23 23:20:27
Node.js
Wasya UK, 2019-08-23 23:20:27

How to make friends server and react?

Wrote a simple server:

router.post('/login', async (ctx, next) => {
  console.log(ctx.request.body.email);
  console.log(ctx.request.body.password);

  await next();
});

And a react site:
handleSubmit = e => {
    e.preventDefault();

    if (this.validateForm() == true) {
      axios
        .post('/api/login', {
          params: {
            email: this.state.email,
            password: this.state.password
          }
        })
        .then(response => {
          console.log(response);
        })
        .catch(err => {
          console.error(err);
        });
    } else {
      alert('incorrect data');
    }
  }

The server is started separately and the site separately. How can I make it so that during development I access the server on port 5000? On production, you need to have .post('/api/login'), because this server will run. I did an eject react and set the proxy in dev server config , but it didn't help. What am I doing wrong?
proxy: {
      '/api': {
        target: 'http://localhost:5000'
      },
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wasya UK, 2019-08-24
@dmc1989

you need to add to package.json"proxy": "http://localhost:5000"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question