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

224
Vistas
Using MirageJS with NextJS API route

I want to call an external API from the api folder from Next.js. I want to call it on server side because the client should not see what URL is called. In the dev environment I use a Mirage server to mock the external API. Is it possible to catch this request with MirageJS?

Some more details:

This is the first call from the client to the API server side.

async function userExists(email: string, callback: (arg: any) => void)  {
    await axios.get('/api/lcm/users/exists/' + email)
        .then(response => {
            logger.info(response)
            callback(response.status)
        })
        .catch(error => {
            logger.error("an error occured in lcmServices, userExists()", error)
    //do something with errors
            callback(error)
            throw error
        });
}

This snippet called from above.

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
    const  mail = req.query.email;

    await axios.get(process.env.NEXT_PUBLIC_LCM_FIRSTRUNNER_URL + '/service/exist/mail/' + mail)
        .then(response => {
            res.status(response.status).send(response.data);
        })
        .catch(error => {
            console.log(error)
            //do something with errors
            throw error
        });

    return res.end(); 
}

Then I have a route in MirageJS which should catch this call above process.env.NEXT_PUBLIC_LCM_FIRSTRUNNER_URL + '/service/exist/mail/' + mail, but it throws an error:

Error: Request failed with status code 404.

Is there a workaround to catch this call?

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