title: Next.js server side api call returns 500 internal server error
body: <p>I'm finally dipping my toe into the world of server side react using <a href="https://nextjs.org/" rel="nofollow noreferrer">Next.js</a>, however I'm pretty stumped with this issue.</p>
  <p>I'm making a call to an API from <code>pages/customer-preferences.tsx</code> using <code>isomorphic-unfetch</code></p>
  <pre><code>CustomerPreferencesPage.getInitialProps = async () =&gt; {
    const res = await fetch(API_URL + '/preference-customer');
    const initialData = await res.json();
    return { initialData };
  };
  </code></pre>
  <p>All works fine locally in <code>dev</code> mode or once built and ran <code>build</code> &gt; <code>start</code>. To host it I'm running it from a docker container <code>node:10</code>, and when I run this locally all is fine also. The issue only happens once it's deployed.</p>
  <p>When I navigate to <code>/</code> and then click a link to <code>/customer-preferences</code> all works as expected. But if I refresh the page or load the page directly at <code>/customer-preferences</code> I see this error from Next.js</p>
  <p><a href="https://i.stack.imgur.com/lcA3S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lcA3S.png" alt="enter image description here" /></a></p>
  <p>So the issue only seems to happen when trying to make the API calls from the server and not the client.</p>
  <p>I've also setup a simple express server to use instead, but not sure if this is necessary?!</p>
  <pre><code>const express = require('express');
  const next = require('next');
  
  const port = parseInt(process.env.PORT, 10) || 3000;
  const dev = process.env.NODE_ENV !== 'production';
  const app = next({ dev });
  const handle = app.getRequestHandler();
  
  app.prepare().then(() =&gt; {
    const server = express();
  
    server.all('*', (req, res) =&gt; {
      return handle(req, res);
    });
  
    server.listen(port, err =&gt; {
      if (err) throw err;
      console.log(`&gt; Ready on http://localhost:${port}`);
    });
  });
  </code></pre>
  <p>When checking the server logs I get this:</p>
  <pre><code>FetchError: request to http://xxx failed, reason: getaddrinfo EAI_AGAIN xxx xxx:80
  </code></pre>
  <p>Any help would be greatly appreciated.</p>