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

368
Visualizações
NextJS /pages/api routes are compiled at runtime

I have a NextJS app which has API routes inside of pages/api. Each route reads from a Singleton, which holds 1 instance of a Redis server connection (ioredis) - so I can reuse 1 connection and not connect multiple times.

I've noticed that when I use these routes, the Singleton is recreated once per route. I can see that NextJS is compiling these at runtime, which makes me think that a new instance of the Singleton is being created for each route - that's causing multiple instances of the Redis connection:

event - compiled client and server successfully in 174 ms (1201 modules)
wait  - compiling /api/rtmtoken...
event - compiled client and server successfully in 106 ms (1202 modules)
wait  - compiling /api/users...
event - compiled client and server successfully in 113 ms (1203 modules)

How do I turn off the compiling at runtime here? Alternatively, is there a better practice for holding 1 instance of a connection to Redis or similar?

Thanks!

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