'Why python server not able to receive and send messages?
I have a chatbot in python and want to integrate it to my react website. I am getting the following error while sending data to python server at localhost:/5000 from localhost:/3000:
Could not proxy request /js/jquery-1.11.0.min.js from localhost:3000 to http://localhost:5000/.
The code for my python and js file:
from flask import Flask
app=Flask(__name__)
@app.route("/members")
def members():
return {"members":["Member1","Member2","Member3"]}
if __name__=="__main__":
app.run(debug=True)
The message file:
import axios from 'axios'
import './Message.css';
import React, {useState,useEffect} from 'react';
const Message=()=>
{
// state ={
// chat:[],
// msg:''
// }
const [chat,setChat]=useState(["hellos zdfgzsdfgsfdg","dfgsdfgsdfgsdfgsdfgs","sdfgsdfgsdfgsdfgsdfgsdfg"]);
const [msg,setMsg]=useState("");
const[data,setData]=useState([{}])
useEffect(()=>{
fetch("/members").then(
res=>res.json()
).then(
data=>{
setData(data)
console.log(data)
}
)
},[])
return(
<div >
</div>
)
}
export default Message;
Solution 1:[1]
axios.get(`${process.env.REACT_APP_API}/members`).then(.......
REACT_APP_API='http://localhost:8000' for example
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mahmoud2020 |
