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

276
Visualizações
How to invalidate array of sluges in Next.js?

Since 12.1.0 it is possible the On-demand Revalidation.

https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration

Sending array of programIds, how can I invalidate array of slugs? I tried this:

export default async function handler(req, res) {
    // Check for secret to confirm this is a valid request
    if (req.query.secret !== process.env.NEXT_PUBLIC_SECRET_TOKEN) {
        return res.status(401).json({ message: 'Invalid token' })
    }

    try {
        const programIds: String[] = req.query.programId
        programIds.map((programId) =>
            await res.unstable_revalidate(`/hu/buyTicket/${programId}`)
        )
        
        return res.json({ revalidated: true })
    } catch (err) {
        // If there was an error, Next.js will continue
        // to show the last successfully generated page
        return res.status(500).send('Error revalidating')
    }
}

I got this error:

'await' expressions are only allowed within async functions and at the top levels of modules.

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

0

.map does not respect await even if you use async. In your situation, you will receive a response before revalidation is completed, which is incorrect behavior.

The correct method should include the usage of Promise.all so that res.json is called only after all the revalidations are completed, and try/catch block can catch error correctly.

  await Promise.all(programIds.map(async (programId) =>
        await res.unstable_revalidate(`/hu/buyTicket/${programId}`)
  ))
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