1

I'm attempting to make an application that has a React frontend (running on port 8080) and an Express-Node.js backend (on port 3000). I'd like for my client to use fetch to request data from my server. So far, what I've read online indicates that I need to add a proxy entry to my package.json with the value of http://localhost:3000. I've done this, my server receives the request correctly, but its response is not what I expect (a JSON object). What am I doing wrong?

//Server
app.get('/search', function(req, res) {
...
      //console.log(section) <-- Is the correct value
      res.json(section);
    })
...
app.listen(3000)


//Client
  handleTouchTap() {
    fetch('/search?crn=10001').then(function(response) { //<-- Hard-coded for testing
      return response; //<-- Does not contain the value of "section" from server
    }).then(function(data) {
            console.log(data); //<-- Likewise, does not contain the value
    });
  }

//From package.json
...
    "proxy": "http://localhost:3000",
...

1 Answer 1

2

You need to pull the json out of your response:

fetch('/search?crn=10001')
  .then(response => response.json())
  .then(section => console.log(section));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.