Hi, i'm trying to get the Astro.request object inside a typescript file - is this possible?
I'm using nodeJs and server mode (no static builds)
Use case: I want to use tRPC middlewares with Astro (without the astro-trpc plugin which works only for very narrow use cases)
How it works:
I have queries and mutations defined with trpc, and i'm building a trpc server instance to be able to use queries and mutations in SSR (instead of using a client instance, which i'm using on client side components)
https://trpc.io/docs/v10/server-side-calls
I've got everything working and a workaround would be to wrap router.createCaller(context) in a function
const rpcServer = (request: AstroRequest) => {
// extract data from request object as const rpcContext = ....
return router.createCaller(rpcContext)
}
But i'd like to avoid having to pass the request object whenever i want to use trpc calls inside .astro files
Edit: For clarification, this typescript file is only used server-side!