title: Fetching local and production on Vercel
body: <p>I have a really serious question I didn't find the answer about Vercel (NextJS).</p>
  <p>I am trying to deploy the project on Versel and I am using some structures to get data from API, example:</p>
  <pre><code>export async function getStaticProps(context) {
    const route = process.env.APIpath + 'api/category/getCategories'; //focusing here, ok on localhost
    const res = await fetch(route)
    const json = await res.json()
    return {
      props: {
        data: json,
        },
    };
  }
  </code></pre>
  <p>As <code>fetch</code> is using only <strong>absolute URL path</strong>, I need to define base url with variable <code>process.env.APIpath</code>.</p>
  <p>With local testing I have <code>process.env.APIpath = 'http://localhost:3000/'</code> <strong>but</strong>: I need to define a production variable for Vercel deployment and <em>I am using serverless functions</em>.</p>
  <p>Some info about Vercel, according to this <a href="https://nextjs.org/docs/basic-features/data-fetching" rel="nofollow noreferrer">documentation</a>, we can actually <code>fetch</code> the data. But during the deployment process, I always have errors on the pages where I am calling <code>fetch</code>, for example:</p>
  <pre><code>//this code triggers an error as code shown above, ok on localhost
  const res = await fetch(process.env.APIpath + 'api/category/getCategory?_id='+ pid, {
      method: 'post',
      body: JSON.stringify(values, null, 2)
  })
  </code></pre>
  <p>I am getting errors because of <code>fetch</code>. Of course, I understand that during the deployment Vercel can't build the production version as I am using &quot;hardcoded&quot; <code>process.env.APIpath</code>.</p>
  <p>How can I define clearly the <code>process.env.APIpath</code> (or any different built variables) to deploy the project? Please, note that every time Versel generates generic project link as <code>nextjs-fhp5exsvo-testing.vercel.app</code>.</p>
  <p>P.S. Will be happy for any help, having an issue with deployment for about 5 days already.</p>