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

120
Visualizações
How do I make an express route to a string that is only loaded after a promise from an API call?
    app.get(`/${sumName}`, async (req, res) => {
        const link = `https://na1.api.riotgames.com/lol/league/v4/challengerleagues/by-queue/RANKED_SOLO_5x5?api_key=${RiotKey}`
        const response = await fetch(link);
        let data = await response.json();
        sumName = data.entries[0].summonerName
        res.send("Works")
    })

The issue I'm having is that sumName is not defined (I believe this is because sumName is only defined within the scope of the function, and doesn't reach the function argument)

However, if I try to pass sumName or anything from data.entries from outside of the function, it will return an object Promise instead of the data. Is there a way to pass this data from inside of the function? Creating a new async function doesn't work because it will still return an object Promise when app.get is called.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You don't need to call app.get to define the route immediately - feel free to do so after the API finishes.

fetch(`https://na1.api.riotgames.com/lol/league/v4/challengerleagues/by-queue/RANKED_SOLO_5x5?api_key=${RiotKey}`)
    .then(res => res.json())
    .then((data) => {
        const sumName = data.entries[0].summonerName;
        app.get(`/${sumName}`, (req, res) => {
            res.send("Works");
        });
    })
    // .catch(handleErrors); // don't forget this
about 4 years ago · Juan Pablo Isaza Relatório
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