FetchError: request to http://localhost:3000//api/getPageInfo failed, reason: connect ECONNREFUSED 127.0.0.1:3000

Viewed 27

In development, the project runs smoothly, but when I try to deploy on vercel I get the error

Error occurred prerendering page "/". FetchError: request to http://localhost:3000/api/getPageInfo failed, reason: connect ECONNREFUSED 127.0.0.1:3000

if i try to access the 'http://localhost:3000/api/getPageInfo' from any browser i can do it, its available. there are 2 more env var, besides NEXT_PUBLIC_BASE_URL, NEXT_PUBLIC_SANITY_DATASET which is = 'production' and NEXT_PUBLIC_SANITY_PROJECT_ID to access the project in sanity studio. they are all configured in vercel

NEXT_PUBLIC_BASE_URL = http://localhost:3000


import type { NextApiRequest, NextApiResponse } from "next";
import { groq } from 'next-sanity';
import { sanityClient } from "../../sanity";
import { Experience } from "../../typings";

const query = groq`
    *[_type == 'experience'] {
        ...,
        technologies[]-> 
    }
`;

type Data = {
    experiences: Experience[];
}

export default async function handler(
    req: NextApiRequest,
    res: NextApiResponse<Data>
) {
    const experiences: Experience[] = await sanityClient.fetch(query);
    res.status(200).json({ experiences })
}







import { Experience } from '../../typings';

export const fetchExperiences = async() => {
        const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/getExperience`);
    
        const data = await res.json()
        const experiences: Experience[] = data.experiences;
        
        return experiences;
}






// ON THE INDEX PAGE (the fetch of the 5 props follows the model above)

export const getStaticProps: GetStaticProps<Props> = async () => {
  const pageInfo: PageInfo = await fetchPageInfo();
  const experiences: Experience[] = await fetchExperiences();
  const skills: Skill[] = await fetchSkills();
  const projects: Project[] = await fetchProjects();
  const socials: Social[] = await fetchSocials();

  return { 
    props: {
      pageInfo,
      experiences,
      skills,
      projects,
      socials,
    },
    revalidate: 10,
  }
}

0 Answers
Related