title: Error: using rewrite in next.config.js to external site works on APIs but not links
body: <p>For several reasons (security, privacy, abstraction in client), I like using the nextJS convention of using the server configuration (next.config.js) to abstract the calls to external sites so that the nomenclature for calling them on the client is lifted into the rewrites of <code>next.config.js</code>.</p>
  <pre class="lang-js prettyprint-override"><code>const gatewayUrl = process.env.GATEWAY_URL ?? 'https://gateway.myco.com';
  const processorUrl = process.env.PROCESSOR_URL ?? 'https://processor.myco.com';
  
  module.exports = (phase) =&gt; {
  
      return {
          async rewrites() {
              return [
                  {
                      source: `/api/proxy/:path*`,
                      destination: `${gatewayUrl}/:path*`
                  },
                  {
                      source: `/process/:path*`,
                      destination: `${processorUrl}/:path*`
                  }
              ];
          },
  </code></pre>
  <p>This works great for all API calls from the client I use through various methods like <code>httpClient.get</code> etc.</p>
  <p>But when I try to send my user to a link (via any call like <code>router.push</code>, <code>window.location.replace</code>) in the client directly (thinking it will be rewritten as the <code>rewrite</code> function implies) it always gives me errors like this:</p>
  <pre><code>Server Error
  Error: getaddrinfo ENOTFOUND processor.myco.com
  
  This error happened while generating the page. Any console logs will be displayed in the terminal window.
  Call Stack
  GetAddrInfoReqWrap.onlookup [as oncomplete]
  dns.js (71:26)
  GetAddrInfoReqWrap.callbackTrampoline
  internal/async_hooks.js (130:17)
  </code></pre>
  <p>I know the target link and its server is running and can be found. That is not the problem.</p>
  <p>Of course, I could just put the whole URL in the clientside call to <code>window.location.replace</code>, but that defeats the purpose of abstracting that redirection into the nextjs server side, since it would go directly to the URL. Also, then I have to move the ENV variable to more public space using the variable name prefix <code>NEXT_PUBLIC_</code> in the env. file which makes it exposed everywhere, and takes away from keeping all this messiness on the server.</p>