Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

479
Views
NextJS getServerSideProps () recupera múltiples puntos finales a la vez con retraso

¿Hay alguna forma de obtener datos de varias rutas API en un solo getServerSideProps() con retraso?

Encontré un error 429 (demasiadas solicitudes) cuando intentaba obtener datos de múltiples puntos finales a la vez con Promise.all() .

¿Hay algún método que pueda usar para obtener los múltiples puntos finales de la matriz con un retraso de 1 segundo cada uno?

 async function getClients () { const res = await fetch('http://localhost:3000/api/clients') const json = await res.json() return Object.entries(json) } async function getDetails (clients) { const details = await Promise.all( clients.map(async (item) => { const url = 'http://localhost:3000/api/clients/' + item.clientId; const res = await fetch(url) const json = await res.json() return json }) ) return details } export async function getServerSideProps() { const clients = await getClients() const details = await getDetails(clients) return { props: { clients, details, }, } }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puede intentar usar el limitador de velocidad que forma parte del paquete async-sema .

También vale la pena señalar que debe evitar llamar a sus rutas API Nextjs desde su función getServerSideProps . Como ya se está ejecutando en el servidor, puede realizar cualquier lógica dentro de sus rutas API directamente y evitar la penalización de un salto de red adicional.

 import { RateLimit } from "async-sema"; async function getClients () { const res = await fetch('http://localhost:3000/api/clients') const json = await res.json() return Object.entries(json) } async function getDetails (clients) { const lim = RateLimit(5); const details = await Promise.all( clients.map(async (item) => { await lim(); const url = 'http://localhost:3000/api/clients/' + item.clientId; const res = await fetch(url) const json = await res.json() return json }) ) return details } export async function getServerSideProps() { const clients = await getClients() const details = await getDetails(clients) return { props: { clients, details, }, } }
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!