async middleware
is it possible to define an async middleware?
I want to do something like this but it throws errors when i start the server
const dbMiddleware = middleware(async ({ path, ctx, next, input }) => {
ctx.path = path;
let session: Pool | null = null;
try {
session = await getSession();
ctx.query = session.query;
let result = await next({ ctx });
if (session)
await session.end();
return result;
} catch (e: any) {
if (session)
await session.end();
}
});
2 Replies
@Barakonda yes async works…where is the exception occurring?
it occures when running it- the build works fine
const dbMiddleware = middleware(async ({ path, ctx, next, input }) => {
^
TypeError: (0 , createRouter_1.middleware) is not a function
nevermind... i didn't notice and i had an import loop.... i really shouldn't code in the middle of the night