tRPCttRPC
Powered by
santiS
tRPC•2y 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,
  }
}
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?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Query param in every client request
zerovbZzerovb / ❓-help
3y ago
how to set request timeout in client
backboneBbackbone / ❓-help
3y ago
Client request headers with createTRPCProxyClient
NeoBeanNNeoBean / ❓-help
2y ago