Skip to content

proxy not working #3557

@sunnyYanan

Description

@sunnyYanan

I nearly create a project using create-react-app.
I set a proxy in package.json just like "proxy":"https://xx.com"

then I write a button on a page and do the fetch action, here is my code:

class App extends Component {
  constructor(props) {
    super(props);
    this.fetch = this.fetch.bind(this);
  }
  fetch() {
    fetch('/getPoplayer.json',{headers:{
      "Accept":"text/html, application/xhtml+xml, application/json, */*"
    }})
    .then(function(response) {
      return response.text()
    }).then(function(json) {
      console.log('parsed json', JSON.parse(json))
    }).catch(function(ex) {
      console.log('parsing failed', ex)
    })
  }
  render() {
    return (
      <div className="App">
        <Button onClick={this.fetch}>测试fetch</Button>
      </div>
    );
  }
}

export default App;

after executing 'npm start' , the request is like this

image

the proxy not works , but I console.log the proxySetting in start.js , it is right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions