0

Basically APIs are working fine in dev mode. but when its come to production its give me an error that data is not defined or failed to collect page data. so, I guess my Apis are not working in getStaticPaths and getStaticProps. So,

what is the proper way to doing it ? how to resolve this issue ? and I tried also in VERCEL but its give me the same error. Can anybody please help me :(

Thanks In Advanced <3

- info Collecting page data .AxiosError: connect ECONNREFUSED ::1:3000
    at AxiosError.from (file:///E:/HUMAIL/NEXT.JS%20FOLDER/ROAD%20TO%20DEVELOPERS/road-to-developers/node_modules/axios/lib/core/AxiosError.js:89:14)

        _currentUrl: 'https://localhost:3000/api/allSchedules',
        [Symbol(kCapture)]: false
      },
      cause: Error: connect ECONNREFUSED ::1:3000
          at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
        errno: -4078,
        code: 'ECONNREFUSED',
        syscall: 'connect',
        address: '::1',
        port: 3000
      }
    }
    Error: Failed to collect page data for /schedules/[schedule_name]

this is how am I doing:

this is env file:

MONGODB_URI=mongodb+srv://username:pass@clustername.v0a9z1l.mongodb.net/?retryWrites=true&w=majority

NEXT_PUBLIC_API_URL_SCHEDULE=https://localhost:3000/api/allSchedules
NEXT_PUBLIC_API_URL_SKILLS=https://localhost:3000/api/getAllSkills
NEXT_PUBLIC_API_BASE_URL=https://localhost:3000

this is my method:

export async function getStaticPaths() {


  const data = await getSchedules();



  const paths = await data.map((item: any) => ({

    params: {
      schedule_name: item.name.toString(),
    },

  }));

  return {

    paths,
    fallback: false

  }

}

getSchedule Function:

import axios from "axios";

export const getSchedules = async () => {


  const api_url: string | undefined = process.env.NEXT_PUBLIC_API_URL_SCHEDULE;

  const res = await axios.get(api_url as string);

  const data = await res.data;

  return data;


}

these methods are working perfectly fine in development mode but I don't know why is not running in production mode..

Humail Saleem
  • 112
  • 1
  • 10

0 Answers0