Getting 'Unhandled Rejection (TypeError): Failed to fetch' error
shubham-aaic opened this issue · comments
Hi @shubham-aaic,
Can you please make sure that you have the Go server & Postgres running. Looks like the above error is because it is unable to get a response back from the Go API server.
In the project root, you can use docker-compose to build the project
docker-compose build
docker-compose up
After running the above two commands you should see an output similar to the one below for docker-compose ps
which means that all the services are up.
$ docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------
todo-fullstack-app-go-gin-postgres-react_go-api_1 /go/bin/build ./wait-for-i ... Up 0.0.0.0:8081->8081/tcp
todo-fullstack-app-go-gin-postgres-react_postgres_1 docker-entrypoint.sh postgres Up 0.0.0.0:50324->5432/tcp
todo-fullstack-app-go-gin-postgres-react_react-app_1 docker-entrypoint.sh npm start Up 0.0.0.0:3000->3000/tcp
Alright, looks like we need to debug it out.
Can you add the following line to componentDidMount()
in frontend/src/components/todolist.js
and restart the docker-compose setup, after that can you please send the console log output once you open the page http://localhost:3000/
and a snapshot of the docker-compose logs if the error pops up again.
componentDidMount() {
fetch("http://localhost:8081/items")
.then(res => res.json())
.then(json => this.setState({ items: json.items }))
.catch(err => console.log(err));
}
btw it says CORS error. I am running this application on ec2-instance!
I got the reason for this error it is a CORS error because when I try to hit the application locally using curl localhost:3000
it returns 200 success code but it doesn't work when accessed from browser. I hope you got the idea now.