Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda