ixartz / Next-JS-Landing-Page-Starter-Template

🚀 Free NextJS Landing Page Template written in Tailwind CSS 3 and TypeScript ⚡️ Made with developer experience first: Next.js 14 + TypeScript + ESLint + Prettier + Husky + Lint-Staged + VSCode + Netlify + PostCSS + Tailwind CSS

Home Page:https://creativedesignsguru.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API call in getServerSideProps not working in production build

ravinleague opened this issue · comments

commented
I have a method that calls backend node js API

export async function getServerSideProps(context:GetServerSidePropsContext){
  const reqUrl = context.req.url;
  const splitUrl = reqUrl?.toString().split('?').pop()?.split('&');

  if(!splitUrl) return null;

  const searchText = splitUrl[0]?.split('=')[1];
  const suburb = splitUrl[1]?.split('=')[1];
  
  if(searchText && suburb){
    
    const _dataService = new ServiceProviderDataService();
    const response = await _dataService.searchAdvertisements(searchText, suburb);
     const searchTitle = `We found ${response.length} search results for ${searchText} in ${suburb} ..`;
      return {
        props: {
          data: response,
          searchTitle:searchTitle,
        },
      };  
  }

  return null;
}
const SearchResultsPage = (data:ISearchResult[],searchTitle:string) => (
  <Main>
    <Head>
      
      <meta
        name="description"
        content={`Elevate your hairstyling experience with Mobile Hairdressers, 
                  the ultimate destination for connecting clients and skilled mobile hairdressers. 
                  Explore our About Us page to learn how we seamlessly bridge the gap between clients and talented stylists, 
                  bringing the salon experience to your doorstep. 
                  Discover the convenience, expertise, and personalized service that define our mobile hairdressing platform`}
      />
    </Head>
    <SearchResults searchTitle={searchTitle} searchResults={data} />
  </Main>
);

The above code works in local (npm run build, npm run start, npm run dev). When I upload to my ubuntu server, the getserversideprops waits a long time and returns a ECONNN TIMEOUT. I can confirm the API is returning data (as I previously said, this is all working well in localhost)





The code you show is not coming from the template, your error should not be related to the template.