MiNiMAL
MiNiMAL
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
app.use('/trpc', async (req, res, next) => {
const client = await getClient()
req.client = client

await createExpressMiddleware({
router: appRouter,
createContext
})(req, res, next)

if (req.client) {
await req.client.release()
}
})
app.use('/trpc', async (req, res, next) => {
const client = await getClient()
req.client = client

await createExpressMiddleware({
router: appRouter,
createContext
})(req, res, next)

if (req.client) {
await req.client.release()
}
})
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
and actually...this can be simplified into just one middleware for /trpc
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
@Alex / KATT 🐱 I think I got this working just with express middleware. Somewhat hacky but...it's working!
app.use(async (req, res, next) => {
const client = await getClient()
req.client = client
next()
})

app.use('/trpc', async (req, res, next) => {
await createExpressMiddleware({
router: appRouter,
createContext,
})(req, res, next)
next()
})

app.use(async (req, res) => {
if (req.client) {
await req.client.release()
}
})
app.use(async (req, res, next) => {
const client = await getClient()
req.client = client
next()
})

app.use('/trpc', async (req, res, next) => {
await createExpressMiddleware({
router: appRouter,
createContext,
})(req, res, next)
next()
})

app.use(async (req, res) => {
if (req.client) {
await req.client.release()
}
})
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
Was there a reason for the removal of teardown? I'm happy to suggest reverting but lack the context.
13 replies
TtRPC
Created by MiNiMAL on 11/2/2023 in #❓-help
Function to release context post-batching?
Thanks, I'll peek at that. I'm also going to experiment with moving the db connection logic onto the express middleware layer
13 replies