Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
Unable to set relative path for the API url in nextjs

I have created a pizza ordering app with nextjs on my local server. I am trying to deploy it to vercel and I am running into problem. My github of the app is :- https://github.com/ajaybirbal/nextjs-pizzaapp

See, my app apps homepage is on localhost:3000. My app gets pizza data from localhost:3000/api/pizzas which gives a list of pizza in json format. As a result I have set my env variables as this: -

.env file - https://github.com/ajaybirbal/nextjs-pizzaapp/blob/main/.env.local

URL_API = http://localhost:3000/api/
NEXT_PUBLIC_API_URL = http://localhost:3000/api/

js file that takes values from env file - https://github.com/ajaybirbal/nextjs-pizzaapp/blob/main/services/pizzaApiUrls.js

const API_URL = process.env.URL_API;
//Url for getting all pizzas
export const ALL_PIZZAS_API_URL = `${API_URL}pizzas`

Now, I am trying to deploy it to vercel. So I changed my URL_API to '/api/' which isn't working. I even tried changing it to 'api' or '/api' or 'api/' without any success. Whole of my applications stop working. I have to type whole of the address with localhost:3000/api/pizzas to make it work or else whole app breaks even on local server.

How do I change it so I can make it production ready? Again here is my github: - https://github.com/ajaybirbal/nextjs-pizzaapp


I am getting this error on vercel console: -

> Build error occurred
TypeError: Cannot read property 'map' of null
    at getStaticPaths (/vercel/path0/.next/server/pages/pizza/[id].js:146:26)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async buildStaticPaths (/vercel/path0/node_modules/next/dist/build/utils.js:498:31)
    at async /vercel/path0/node_modules/next/dist/build/utils.js:641:119
    at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:75:20) {
  type: 'TypeError'
}

It is line 61 of this: - https://github.com/ajaybirbal/nextjs-pizzaapp/blob/main/pages/pizza/%5Bid%5D.js

So map is not getting json data.

I tried changing env variables on vercel like this: - https://nextjs-pizzaapp.vercel.app/api/

I found the domain on settings->Domains. Also, its showing Failed to Assign

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda