[ I’m starting in web development. Now, I am trying to add the backend part of the project. the login function is supposed obviously to fetch data from the client but for now I just have a simple function in api.js where I want to centralize my api functions: and finally the index.js
I am not copying users.js and other objects for simplicity but all classes works fine when going to http://localhost:3000/ or http://localhost:3000/users however when I click on the button, I get the error Unhandled Rejection (TypeError): Failed to fetch. Any idea what I am missing? ,
, At first, make sure the endpoint of your API is correct and the server is running successfully without any issue. You can use Postman to test your API. Once your API is running successfully then you can make a request from the front-end(react.js).
Use catch for handling all errors. know more Thank you. , check your server is running or not. if not run it again by using node index.js. and your server-side port should be different , include app.use(cors({origin: “*”,})) in your backend index.js ] How do you fix TypeError failed to fetch?To solve the "TypeError: Failed to fetch", make sure to pass the correct configuration to the fetch method, including the URL, HTTP method and headers, and verify that the server you're making a request to is setting the correct CORS headers with the response.
What is the meaning of Failed to fetch?When you see an error saying "Failed to fetch" or get an ICE error this means that there is a connectivity issue between you and Lookback. Typically this is related to a firewall blocking your connection in some way.
|