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
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