Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
How to init state for API server in NextJs

I am trying to have some instance loaded (run some init function) before my NextJs server can serve my API. For example:

// src/pages/api/getSelfCakeStats.ts
export default async function getSelfCakeStats(
  req: NextApiRequest,
  res: NextApiResponse
) {
  setChainId(ChainId.MAINNET); // <- I want to run this before the server is online
  initProvider();              // <- I want to run this before the server is online
...
}

It is doable Is there anyway I can do it explicitly in any given file of NextJs structure? the next.config.js is very limited in syntax so it is not an ideal place to run the logic while singleton pattern might do the job but it would get my instance to be intialized implicitly (init when null)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda