update docs

This commit is contained in:
wobsoriano
2022-11-24 12:51:28 -08:00
parent b27938f108
commit 68003e9c3e
4 changed files with 52 additions and 9 deletions

View File

@@ -0,0 +1,42 @@
---
title: Headers
---
# Headers
We can use the built-in `useRequestHeaders` to access/pass headers to any future internal requests during SSR.
```ts [plugins/client.ts]
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,
},
}
})
```
```ts [server/trpc/context.ts]
export function createContext (event: H3Event) {
console.log('cookies', parseCookies(event))
return {}
}
```