mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
781 B
781 B
title
| title |
|---|
| Headers |
Headers
We can use the built-in useRequestHeaders to access/pass headers to any future internal requests during SSR.
import { httpBatchLink, createTRPCProxyClient } from '@trpc/client'
import type { AppRouter } from '@/server/trpc/routers'
export default defineNuxtPlugin(() => {
const headers = useRequestHeaders()
const client = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
headers() {
return {
...unref(headers)
}
}
}),
],
})
return {
provide: {
client,
},
}
})
export function createContext (event: H3Event) {
console.log('cookies', parseCookies(event))
return {}
}