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

220
Visualizações
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 à 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