Answers for "Uncaught (in promise) TypeError: Failed to fetch"

0

TypeError: Failed to fetch

//The Problem is caused by Cross-origin (CORS)
//make sure you allow the origin you want your app to connect with:
Access-Control-Allow-Origin = "domain.com"

//or to allow all
Access-Control-Allow-Origin = "*"


//node js
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});
Posted by: Guest on August-07-2021
1

fetch error handling js

export async function getStaticProps(context) {
  const res = await fetch(`https://...`)
  const data = await res.json()

  //use this statement for the program not to crush but go back to the home page
  if (!data) {
    return {
      redirect: {
        destination: '/',
        permanent: false,
      },
    }
  }

  return {
    props: {}, // will be passed to the page component as props
  }
}
Posted by: Guest on December-08-2020

Code answers related to "Uncaught (in promise) TypeError: Failed to fetch"

Browse Popular Code Answers by Language