santiS
tRPC2y ago
5 replies
santi

Create client that is used in every request, without re-creating client

Hi all,

Consider the following
export const createContextInner = async ({
  req,
  res,
}: {
  req?: Context['req']
  res?: Context['res']
}): Promise<Context> => {
  const app = await NestFactory.createApplicationContext(AppModule)
  return {
    app,
    prisma,
    req,
    res,
    supabaseServerClient: null,
    user: null,
  }
}

This is annoying in local development because it needs to create the nest app for every request. The same thing with the prisma client.

We'd like to create this once and use in every request. Is this possible?
Was this page helpful?