Owali Ullah Shawon
Owali Ullah Shawon

Reputation: 57

Server Error Error: Request failed with status code 500

 export const getServerSideProps = async () => {
      const res = await axios.get('http://localhost:3000/api/products');
      return {
        props: {
          kebabList: res.data
        }
      }
    };




    // get all the products
  if (method === "GET") {
    try {
      const products = await Product.find();
      res.status(200).json(products);
    } catch (err) {
      res.status(500).json(err);
    }
  }

When I first load the app it is showing this error Server Error Error: Request failed with status code 500

If I reload again then it works fine but after deploying on vercel the error is permanent

Upvotes: 0

Views: 2427

Answers (1)

Sajeeb M Ahamed
Sajeeb M Ahamed

Reputation: 151

When you have deployed your app on vercel, your API url might be changed http://localhost:3000 to http://your-domain(live-url).com.

    export const getServerSideProps = async () => {
      const res = await axios.get('http://your-domain(live-url).com/api/products'); //  please focus on this line. I belive you have messed up here
      return {
        props: {
          kebabList: res.data
        }
      }
    };

    // get all the products
  if (method === "GET") {
    try {
      const products = await Product.find();
      res.status(200).json(products);
    } catch (err) {
      res.status(500).json(err);
    }
  }

Upvotes: 1

Related Questions