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

97
Vistas
How to set up my project to handle Axios/Fetch CRUD requests for Heroku

I'm quite new to Heroku and backend overall.. I'm trying to deploy an app to heroku which makes POST requests in the frontend to the backend server (MERN stack). Everything works fine ONLY on the localhost.

I tried setting the server link to "page_name.herokuapp.com" and even left the url empty with "/refresh" and "/" but it does not seem to recognize that I'm making POST requests.

I heard about environmental variables - but I'm not sure how to set them up. Do I make an env file and put the const baseUrl in there or should I do it on the settings in Heroku ?

Sorry if this is a silly mistake, but I cant figure out how to make my frontend/backend cooperate.

const baseUrl = process.env.baseURL || "http://localhost:3001";

useEffect(() => {
    fetch(`${baseUrl}/`)
    .then((res) => res.json())
    .then((res) => setStocks(res))
  },[]); 

const handleRefresh = (e) => {
  e.preventDefault();
  const res = e.target.dataset.value;

  if (stocks !== '') {

    const options = 
    {
      method: 'POST',
      headers: {
        'Content-Type':  'application/json'
      },
      body: JSON.stringify({res}),
    };

    const response = fetch(`${baseUrl}/refresh`, options);

  };
}

these are the package.json scripts file for react/frontend

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
  },

Procfile:

web:nodemon backend/index.js // tried node backend/index.js as well

https://github.com/szumi112/stockpricesapp - here's my github for more information

Not sure what else I can do to figure this out. Let me know if more information is needed.

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