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?
BeBoRE
BeBoRE41d ago
Move it outside of the context creator?
santi
santi41d ago
To where though? It'd be ideal here
export const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape
},
})
export const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape
},
})
BeBoRE
BeBoRE41d ago
The global context
More Posts
Using TRPC Server Caller in client side.What's up TRPCer. so i'm currently working in vanilla react app with seperate backend in .NET, in pAnyone has successfully setup a websockets subscription with an input ?Hi guys, here is my environment: *** node v20.11.1 * yarn@4.1.0 * trpc 11.0.0-next-beta.294 * next 1Middleware context changes aren't applied to `responseMeta(opts)` optionsIn our middleware I extend the ctx like this: ```ts const public = t.middleware(async ({ next, ctx Cookie authentication flowHello can i get a bit of a help and explanation please? Im frontend learning backend on trpc, I haveIs It Possible to use methodOverride with createNextApiHandler?I'm trying to build queries for grids and filter and sort object could get very large which is exceeLambda container reuseIn high traffic environments lambda reuses the same container to serve multiple requests. The lambdaTrouble with Vercel and deployment URLHey I've been having a problem with nextjs deploying to vercel. In localhost the calls to the backen1 trpc api server for 1 or many clients.I'm a beginner, working on two monorepo projects that resides on the same folder, each of which withError formatting with trpcExpress.createExpressMiddlewareI'm trying to figure out how to do error formatting but it's unclear how to do it in the context of Tried to access "$types.prototype" which is not available at runtimeIm getting this weird errors every thing was good until I migrated to trpc 11 which for some reason type safety with metahow do I get the meta types to work correctly?Confused by the many examples and docs of implementing trpc, next.js (app router), and clerk.To show an examples of the many variants an implementations here is an example: In TRPC Docs: http