'Proxy error: Could not proxy request /time from localhost:3000 to http://localhost:5000
I am working on a simple React-Flask App which aims to fetch the current time from the Back-end and display it on the Front-end.
I have the Flask Back-end and the React Front-end both running together at the same time.
The back-end is working perfectly fine on port 5000
:
Fetch call '/time'
from the front-end is unable to fetch the current time even tho I have my proxy defined in the package.json
:
"proxy": "http://localhost:5000"
Front-end:
function App() {
const [currentTime, setCurrentTime] = useState(0);
const getCurrentTime = async (API) => {
const response = await fetch(API);
const jsonData = await response.json();
setCurrentTime(jsonData.time);
console.log(jsonData);
};
useEffect(() => {
// getCurrentTime('http://localhost:5000/time');
getCurrentTime('/time');
}, []);
I have tried the methods discussed here. But none of them seems to work for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|