why fetch from react to flask back end not working

Solutions on MaxInterview for why fetch from react to flask back end not working by the best coders in the world

showing results for - "why fetch from react to flask back end not working"
Alfonse
25 Oct 2019
1//There are some packages you can use like fetch-with-proxy or node-https-proxy-agent, fetch-with-proxy can get HTTP_PROXY env var to set proxy, and you can use the other create proxy agent.
2
3//But I recommend that to use other package to send request like axios.
4
5import axios from 'axios';
6const axios_ = axios.create({
7  baseURL: 'http://localhost:5000',
8  headers: { 'Content-Type': 'application/json' },
9})
10
11class App extends React.Component  {
12  componentDidMount() {
13    axios_.get('/')
14      .then(response => {
15        console.log(response.text()) //Here is the text() i said before
16        this.setState({ snippets: response.data })
17      })
18      .catch(error => {
19        console.log(error)
20      });
21  }
22...}
23
Charlotte
30 Jun 2018
1Latest update: Sorry about I misunderstood about proxy in nodejs, and fetch() can support this kind of proxy.
2
3//After I do some trial and error, you just need to change you path '/' to '/something_else' and the proxy work well.
4
5//Wrong information:
6
7//This is not issue about python and flask.
8
9//You use fetch() in javascript, and this is native js function, so it is not related with proxy you set in package.json.
10
11//If you want to use fetch() to get other port, you have to give it the whole url http://localhost:5000/ or you will get the same port of you react app.
12
13fetch('http://localhost:5000/')
14      .then(response => {
15        console.log(response.text()) //Here is the text() i said before
16        this.setState({ snippets: response.data })
17      })
18      .catch(error => {
19        console.log(error)
20      });
21
queries leading to this page
run flask and react togetherreact js python flask build apppython flask react tutorialreact app with flask backendhow to connect react to flask 3fflask and reactcreating flask api with react front endflask and react tutorial for windos developmentintegrating react with flaskflask react apphow to implement react js with flaskhow to use react with flaskflask react rest apireact front end flask back endpython flask and react tutorialfetching data from flask with reactflask backend with reactreact app with flask tutorialflask reactreact python backendhow to render react with flaskreact and flask apireactjs and flaskform routes for flask react appflask with reactapi flask react fontendrunning react script without jsx on flaskreact flask appto fetch data from reactjs to flaskflask return react frontendflask and react nativesimple flask react appfrontend flask projectget call from react to flaskworking with react and flask python making api request and render them in react simplepython flask and react tutorial post jsonconnect react to flask backendreact front end flask backendwhy fetch from react to flask back end not workingreact flask integrationflask server react buildconnnect react with python flaskpython flask reactjs tutorialsessions with a react 2fredux frontend and flask api backendflask react requestsbuilding a full app react and flask backendget call from react to flask hookflask api with react frontendpython flask and reactflask 2b reactreact with flaskflask fron endhow to use useeffect on flask apibuilding a full app react and flaskreact and flaskhow to connect react to flaskhow to fetch data from flask to reacthow to incorporate react js files to flaskflask js projectwhy fetch from react to flask back end not working